htod - convert C .h files to D import files

Lionello Lunesu lio at lunesu.remove.com
Wed May 24 23:56:54 PDT 2006


BCS wrote:
> In article <e52ivj$3am$1 at digitaldaemon.com>, Tom S says...
>> BCS wrote:
>>> Walter Bright wrote:
>>>> I'm not sure how useful this will be.
>>>>
>>>> Here it is: http://www.digitalmars.com/d/htod.html
>>>
>>> One case that it doesn't handle but would seem to be simple is:
>>>
>>> #define FOO "bar"
>>>   |
>>>   v
>>> const char[] FOO = "bar\0"; //explicitly null terminate
>> Why would you need it to be explicitly null terminated ? D string 
>> literals have a zero anyway just after their normal data (it's not 
>> reflected by the 'length' property, but it's there).
>>
> 
> #1 because that behavior it not in standard (AFAIK)
> 
> #2 copying
> 
> <code file=a.h>
> #define FOO "start"
> #define FOO "stop"
> int func(char* string);
> <\code>
> 
> <code file=b.d>
> import a;
> ..
> char[] command = FOO;
> ..
> char[] use = command.dup;  // don't known why, but someone going to do it
> ..
> func(use.prt);   // now what??
> ..
> <\code>

But that's simply a bug in the code, not in the "header".
What if "use" included the zero terminator, what would "use ~= "t";" 
result it? A "t" after the zero terminator? So, either the append code 
would have to strip zero terminators before appending (sure hope it 
won't), or the length property should not include the zero, which is 
exactly what's being done now.

L.



More information about the Digitalmars-d-announce mailing list