www.digitalmars.com         C & C++   DMDScript  

D - string inconsistencies?

It seems to me that that are some inconsistencies in how strings are 
handled.  For example,

   const char[11] a = "a";   // okay
   char[11]       b = "a";   // runtime error

These should be handled the same.

Also, this causes some issues in calls to C API calls.  Suppose that 
there is a function:

    void foo( char *p, int *len );

which fills in p with values and sets len to the length.  You can call 
the function like:

    char[maxsize] myp;
    int mylen;
    foo( myp, &mylen );

but now, the length of myp is set to maxsize, and the comparison 
operators don't work.  If the value placed into myp was "xxx", then

    char[] myvalue = "xxx";
    if (myvalue == myp || icmp( myvalue, myp ))

is always false because it appears that the lengths don't match.  If you 

     printf( "%.*s\n", myp );

it knows the length of myp.  It makes sense that the cmp() and icmp() 
routines would also, and do the comparison based on that.
Mar 13 2004