lua-users home
lua-l archive

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


Julien Cugnière skrev:
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;


No, &regkey1 is not a constant expression, although the result is constant.

I would use the __FILE__ and __LINE__ macros to get unique values,
unless space is an issue.

Something like:

#define STRINGIFY(a)	#a
#define SAPPEND(s,i)	s "" STRINGIFY(i)
#define UNIQUE_KEY	SAPPEND(__FILE__, __FILE__)

static const char* unique_key = UNIQUE_KEY;

// just make sure not to have more than one key-macro per line


Regards,
	Andreas