I am working on some legacy C code and have come accross two strange macro definitions. They don’t look right, and are also responsible for some compiler warnings (warning: left-hand operand of comma expression has no effect), which took me several hours to finally track down to these macros.
Can anyone tell me if they are correct (I suspect not), and if not, how do I fix them?
#define MAX_MEMORY_BLOCK (sizeof(size_t)==2,65535,2147483647)
#define MAX_ARRAY_SIZE (sizeof(size_t)==2,16384,1073741824)
They contain comma operators; only the last value ‘counts’, so they are equivalent to:
Alternatively, someone forgot that the ternary operator uses
?::However, there are few modern systems where
sizeof(size_t) == 2(though there probably are some, especially in the embedded computing world).