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

Re: Question on draft-ietf-ldapext-ldap-c-api-01.txt



On Mon, 16 Nov 1998, Ravindra Iyer wrote:
> Since it standard practice for widely exposed APIs to indicate which 
> parameters are modified and which are not, when the API is called.

I'd argue that the API should use const not for tradition, but because
it's really useful to eliminate several sources of programmer error.  I
started using const in APIs recently and it's been wonderful.  Advantages
include:

* You can use "const static" variables in a thread-safe program, but not
  vanilla "static" variables.  You can use:
  "grep static *.c | grep -v const" to hunt down potential threadding
   problems.

* It allows additional compiler optimizations

* It allows one to use read-only strings much more easily

* It weeds out bad code which has unintended side effects (e.g. downcasing
  a string which might be reused later).

Consider this a strong second to adding "const" to the API wherever
possible.

		- Chris