c - Compile time concatenation of computed string literals -


we can concatenate adjacent string literals so:

puts( "abc" "def" ); 

however, msvc fails strange error when try this:

puts( ("abc") ("def") ); 

which means can single computation outputting string literal so:

puts( num_elements>125?"warning":"ok" ) 

but can't concatenate string literals output multiple of these, such as:

#define some_setting 0x0b //i wish there binary literals #define bit_str(x,n) ((x>>n)&1?"1":"0") #define bit_str4(x) bit_str(x,3) bit_str(x,2) bit_str(x,1) bit_str(x,0)  ...  puts( "initializing hardware setting: " bit_str4(some_setting) ); 

edit: question is... correct way concatenate compile time computed string literals?

bit_str(some_setting, 3), take example, can indeed computed on runtime: results (0?"1":"0"), in turn results pointer constant string "0", not string literal longer.

string literals can concatenated, constant pointers constant strings can't. that's difference.


Comments