OT: What causes the Segfault in the following?

Steven Schveighoffer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Aug 3 19:36:21 PDT 2017


On 8/3/17 10:14 PM, Andrew Edwards wrote:
> Steven Schveighoffer wrote:
>> On 8/3/17 9:12 PM, Andrew Edwards wrote:
>>> Andrew Edwards wrote:
>>>
>>> Just in case... here are the two functions being called in main():
>>>
>>> https://github.com/vurtun/nuklear/blob/master/nuklear.h#L5695-L5722
>>
>> Can you show how you declared these in D? It's important. I think what's
>> happening is that the nk_color_hex_rgb is incorrectly defined. I think
>> you should *always* get segfault, with or without any of those arrays.
>>
> 
> I certainly can, but the problem is completely in C, I'm not having any 
> problems in D. In this case, I've simply copied the two functions to 
> test.c and inserted main().

Oh. Then Ali is correct. I assumed that char *s was initialized to null 
because it was D, and maybe you were passing s by reference incorrectly. 
But actually, you are in c, so s can point anywhere.

Yeah, you need to declare an array instead of just a pointer.

char s[20] should work.

-Steve


More information about the Digitalmars-d-learn mailing list