tags:

views:

82

answers:

2

lets say I have this

char *something[] = { 
    "/bi", 
    "-c", 
    "5", 
    NULL, 
    NULL 
};

but I want to declare it in hex, how would I do this; compiler keeps erroring out on me:

char *something[] = { 
    {0x2f,0x62,0x69},
    {0x2d,0x63},
    {0x35},
    {0x00}, 
    {0x00}
};

to add something else to this, is 0x00 ALWAYS null? does 0x00 always translate to NULL on systems where NULL is -1 for example?

+6  A: 

You can use hexadecimal escape sequences within a string literal. For example:

char *something[] = { 
    "\x2f\x62\x69",
    "\x2d\x63"
}; 
James McNellis
awsome, are they auto null terminated or does a \x00 need to be added at the end of each index?
@bstullkid: They are just string literals with escape sequences inside of them, so, yes, they are null-terminated.
James McNellis
check my edit, if you can answer that thx.
The string literals in double quotes are auto NUL-terminated (with the character '\0', i.e. zero), but the array of pointers to char is not auto NULL-terminated with a NULL pointer.
Arkku
+1  A: 

To answer your question about NULL and the null pointer: the macro NULL is always 0. The compiler then converts that to an appropriate null pointer. The comp.lang.c FAQ has an entire section explaining this more thoroughly.

jamesdlin
+1 for making the assumption that script-kiddie-gamerz-dude will actually read. http://stackoverflow.com/questions/2888915/what-does-this-attempted-trojan-horse-code-do/2888941#2888941
msw