C API / const char *text / std.string.toStringz pointer is always NULL on C side

kinke noone at nowhere.com
Sat May 19 17:50:37 UTC 2018


On Saturday, 19 May 2018 at 17:33:08 UTC, Robert M. Münch wrote:
> On 2018-05-18 14:42:17 +0000, Adam D. Ruppe said:
>> A value struct return is actually done via a hidden pointer 
>> parameter (so the function can construct it in-place for the 
>> caller, a standard optimization), so it just shifted all the 
>> other arguments to the side, causing one of those 0's to be 
>> interpreted as the string.
>
> [...]
>
> Is this somehwere documented?

https://docs.microsoft.com/en-us/cpp/build/return-values-cpp:

> Otherwise, the caller assumes the responsibility of allocating
> memory and passing a pointer for the return value as the first
> argument. Subsequent arguments are then shifted one argument
> to the right.


More information about the Digitalmars-d-learn mailing list