const char* or const(char)* when porting C headers?

Gary Willoughby dev at nomad.so
Sun Dec 22 09:39:37 PST 2013


On Sunday, 22 December 2013 at 16:45:15 UTC, Benjamin Thaut wrote:
> Am 22.12.2013 17:02, schrieb Gary Willoughby:
>> On Sunday, 22 December 2013 at 15:49:43 UTC, Gary Willoughby 
>> wrote:
>>
>>> Thanks, that makes sense. But how would i port this parameter:
>>
>> and these:
>>
>> CONST84 char **tablePtr = ?
>> CONST84 char ***argvPtr = ?
>
> In C/C++ the const always applies to whatever is left of it. If 
> there is nothing left of it, it applies to what is right to it.
>
> So
> "const char**" is equivalent to "char const **". That means the 
> only part that is const is the char. In D const applies to 
> whatever is inside the parantheses.
> So the equivalent in D would be
>
> const(char)** and const(char)***
>
> If you have something like the following in C:
>
> const char * const
>
> the D equivalent would be
> const(char*)
>
> Note that the star is included in the parantheses here, because 
> the pointer is const to, not only the data it points to.
>
> the D type: const(char**) would be equivalent to C: char const 
> * const * const. (But you won't ever needs this)
>
> Kind Regards
> Benjamin Thaut

Ah right, so:

struct Tcl_Obj * CONST * objv

would be:

const(Tcl_Obj*)* objv  or  const(Tcl_Obj*)[] objv


More information about the Digitalmars-d-learn mailing list