lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On 12/2/2011 5:31 AM, Luiz Henrique de Figueiredo wrote:
'mykey' could be changed to a string it doesn't have to be an 'int'.

Note that I'm using the address of that int, not its value.
This address is guaranteed to be unique to the module.

For this reason, I think that

static char *mykey=MY_MODULE_NAME;

should be

static char mykey[]={MY_MODULE_NAME};

just in case the compiler removes duplicate copies of strings.

Using an array guarantees a unique address even if the string is used
elsewhere, even by a different module.



First of all, thanks for the tip.

I found out that with cygwin's gcc, and windows's ddk compiler (/GF option), the following works the same as the one above with {MY_MODULE_NAME}

static char mykey[]=MY_MODULE_NAME;

In any case, it's an eye opener, and I have been writing C for 10-15 years.

So I guess the important thing here, is that ARRAY of CHARS is being allocated, rather than POINTER to STRING. It also makes whole lot difference now of "char* key" vs "char key[]".