Re: OT: What causes the Segfault in the following?

2017-08-04 Thread Kagamin via Digitalmars-d-learn
On Friday, 4 August 2017 at 02:38:10 UTC, Andrew Edwards wrote: OK, I was is indeed the problem. I was thinking for some reason that s gets initialized inside nk_color_hex_rgb() Usually C functions don't allocate memory. And when they do, they do it in unique ways, which is a PITA, that's why

Re: OT: What causes the Segfault in the following?

2017-08-03 Thread Andrew Edwards via Digitalmars-d-learn
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

Re: OT: What causes the Segfault in the following?

2017-08-03 Thread Andrew Edwards via Digitalmars-d-learn
Ali Çehreli wrote: On 08/03/2017 06:02 PM, Andrew Edwards wrote: char *s; That's an uninitialized C string. OK, I was is indeed the problem. I was thinking for some reason that s gets initialized inside nk_color_hex_rgb() but it's expecting to an array to work with. I actually

Re: OT: What causes the Segfault in the following?

2017-08-03 Thread Andrew Edwards via Digitalmars-d-learn
Ali Çehreli wrote: On 08/03/2017 06:02 PM, Andrew Edwards wrote: char *s; That's an uninitialized C string. OK, I was is indeed the problem. I was thinking for some reason that s gets initialized inside nk_color_hex_rgb() but it's expecting to an array to work with. I actually

Re: OT: What causes the Segfault in the following?

2017-08-03 Thread Steven Schveighoffer via Digitalmars-d-learn
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

Re: OT: What causes the Segfault in the following?

2017-08-03 Thread Andrew Edwards via Digitalmars-d-learn
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

Re: OT: What causes the Segfault in the following?

2017-08-03 Thread Steven Schveighoffer via Digitalmars-d-learn
On 8/3/17 9:12 PM, Andrew Edwards wrote: Andrew Edwards wrote: int main() { //int wierd[4]; struct nk_color str = nk_rgba_hex("#deadbeef"); //int wierd[4]; char *s; //int wierd[4]; nk_color_hex_rgb(s, str); //int wierd[4]; printf("(%d,%d,%d)\n",str.r, str.g,

Re: OT: What causes the Segfault in the following?

2017-08-03 Thread Ali Çehreli via Digitalmars-d-learn
On 08/03/2017 06:02 PM, Andrew Edwards wrote: > char *s; That's an uninitialized C string. > nk_color_hex_rgb(s, str); That function is expecting it to have at least 7 chars when doing things like output[1] = (char)NK_TO_HEX((col.r & 0x0F)); So you have to have a proper

Re: OT: What causes the Segfault in the following?

2017-08-03 Thread Andrew Edwards via Digitalmars-d-learn
Andrew Edwards wrote: int main() { //int wierd[4]; struct nk_color str = nk_rgba_hex("#deadbeef"); //int wierd[4]; char *s; //int wierd[4]; nk_color_hex_rgb(s, str); //int wierd[4]; printf("(%d,%d,%d)\n",str.r, str.g, str.b); //int wierd[4]; printf("%s\n",

OT: What causes the Segfault in the following?

2017-08-03 Thread Andrew Edwards via Digitalmars-d-learn
int main() { //int wierd[4]; struct nk_color str = nk_rgba_hex("#deadbeef"); //int wierd[4]; char *s; //int wierd[4]; nk_color_hex_rgb(s, str); //int wierd[4]; printf("(%d,%d,%d)\n",str.r, str.g, str.b); //int wierd[4]; printf("%s\n", s); //int