OT: What causes the Segfault in the following?

Andrew Edwards via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Aug 3 19:39:20 PDT 2017


Steven Schveighoffer wrote:
> On 8/3/17 10:14 PM, Andrew Edwards wrote:
>>
>> 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

Much appreciated.


More information about the Digitalmars-d-learn mailing list