lua-users home
lua-l archive

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


On Friday 02, 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.

You are right.  Checking the binary the string is located in the read-only 
"data.rel.ro" section, which means the compiler can merge duplicate strings.  
Changing it to an array of chars moves it to the read-write "data" section.

I though I was being safe by not using "static const char *".

-- 
Robert G. Jakabosky