lua-users home
lua-l archive

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


2006/6/24, Mike Pall <mikelu-0606@mike.de>:
static const int regkey_foo = 1;
static const int regkey_bar = 1;
[...]
The problem is that the compiler/linker may decide to join
constants with identical _values_. Unfortunately this makes the
_addresses_ the same, too.

Wow, that's interesting.

Solution:
- Or use the addresses of non-const static variables.

Hmm, pushing the idea further, couldn't a smart optimizing compiler
automatically constify non-const variables that the code does not
modify ? You would then have to use volatile non-const static
variables...

Or is the compiler able to make any assumptions about constness once
you take the address of a variable and cast it to (void*) ?

Anyway, here is a simple way to ensure that your constants are unique
(assuming this legal C):

   static const void* regkey1 = &regkey1;
   static const void* regkey2 = &regkey2;

--
Julien Cugnière