[Date Prev][Date Next] [Chronological] [Thread] [Top]

Re: char* parameters -> const char* ?



BTW, a related detail -- this declaration is good in C++, but not in C:

     int ldap_search(
                     LDAP *             ld,
                     char const *       base,
                     int                scope,
                     char const *       filter,
>>>>                 char const *const *attrs,
                     int                attrsonly
                     );

A char** can be passed to attrs in C++, but not in C - due to a bug in
the C standard.  `char const **attrs' can *not* be passed a `char**'[1].

So anyway, since you were talking about C++ classes, maybe you'll want

     int ldap_search(
                     LDAP *             ld,
                     char const *       base,
                     int                scope,
                     char const *       filter,
                     char LDAP_CCCONST *LDAP_CCCONST *attrs,
                     int                attrsonly
                     );

where LDAP_CCCONST is something like

     #ifdef LDAP_CCCONST
     #elif defined(__cplusplus)
     #  define LDAP_CCCONST const
     #else
     #  define LDAP_CCCONST
     #endif

But I'm not going to trash the mailinglist with that piece of obscurity
unless you want to do it.



[1] Allowing a `const char**' to receive a `char**' would open a hole in
const-checking:

	void bogus ( const char **a, char *b )
	{
		*a = b;
		strcpy(b, "writing to const char **a");
	}

-- 
Hallvard