While answering a question on the ATMega32 baudrate, I was reminded of a problem I'm having....
Using the most excellent latest version of WinAVR...
I'm cleaning up my code in proper .h and .c files and want to compile lines based on #define values (specifically for uart frame setting) something like this:
#define frm '8N1' // or '7N1' or '7E1' #if frm=='8N1' ... set the bits for 8N1 #warning "Set for 8N1" #elif frm=='7N1' ... set for 7N1 #warning "set for 7N1" #elif frm=='7E1' .. set for 7E1 #warning "Set for 7E1" #else #error "Error - no valid frame set" #endif
The above example does not work but should be valid according the the GNU CPP (C Pre Processor) docs.
If I change to numerical values it works so...
#define frm 1 // 8N1=1 or 2=7N1 or 3=7E1 #if frm==1 ... set the bits for 8N1 #warning "set for 8N1" #elif frm==2 ... set for 7N1 #warning "set for 7N1" #elif frm==3 .. set for 7E1 #warning "set for 7E1" #else #error "Error - no valid frame set" #endif
Obviously I can get around the problem using the second code, but just curious as to why the first code does not work (no error message either). Should it or is it a bug?
Also ... the #warning messages never come out to the console (output) window in either version!! If I change the #warning to #error they are output. is there a makefile option setting for this? I thought -Wall did that?
Again, not a really big deal, but a little burr under the saddle.