Jul 11, 2002 #1 greadey Technical User Oct 25, 2001 231 GB When you use a #define pragma, what is the type of identifier created, for example; #define BAUD 9600 // is BAUD an int or a char[] #define PARITY 8N1 // Same question. Thanks for your help, greadey.
When you use a #define pragma, what is the type of identifier created, for example; #define BAUD 9600 // is BAUD an int or a char[] #define PARITY 8N1 // Same question. Thanks for your help, greadey.
Jul 11, 2002 #2 smaniraja Programmer Feb 19, 2001 129 IN Just the macro calls (BAUD or PARITY) are replaced by the defined constants (9600 or 8N1) in the program by the preprocessor. After this preprocessor substitution the compiler will do its work. So 9600, and 8N1 will be treated based on the code. --Maniraja Upvote 0 Downvote
Just the macro calls (BAUD or PARITY) are replaced by the defined constants (9600 or 8N1) in the program by the preprocessor. After this preprocessor substitution the compiler will do its work. So 9600, and 8N1 will be treated based on the code. --Maniraja
Jul 11, 2002 #3 tdatgod Programmer Jul 21, 2001 601 US Hi, The Bottom line is #defines are a simple TEXT SUBSTITUTION mechanism and what their types are is dependent on where the text is substituted. Most likely #define BAUD 9600 is will be used integer in the code #define PASSWD "passwd" will be used in place of a char[] in the code. #define PI 3.14 will probably be used as a float. however if it all depends on where you use it. printf("The Baud is %d\n",BAUD ); will become printf("The Baud is %d\n",9600 ); and the compiler would allow this. It will be an integer however printf("The Baud is " #BAUD "\n" will be translated as a string printf("The Baud is " "9600" "\n" now if you had #define PARITY 8N1 and tried printf("Parity is %s\n", PARITY); this would translate to printf("Pariry is %s\n", 8N1); and the compile would flag this as an error because 'N' is not a number. however printf("Parity is %s\n", #PARITY); this would translate to printf("Pariry is %s\n", "8N1" and that is perfectly fine. ---- Upvote 0 Downvote
Hi, The Bottom line is #defines are a simple TEXT SUBSTITUTION mechanism and what their types are is dependent on where the text is substituted. Most likely #define BAUD 9600 is will be used integer in the code #define PASSWD "passwd" will be used in place of a char[] in the code. #define PI 3.14 will probably be used as a float. however if it all depends on where you use it. printf("The Baud is %d\n",BAUD ); will become printf("The Baud is %d\n",9600 ); and the compiler would allow this. It will be an integer however printf("The Baud is " #BAUD "\n" will be translated as a string printf("The Baud is " "9600" "\n" now if you had #define PARITY 8N1 and tried printf("Parity is %s\n", PARITY); this would translate to printf("Pariry is %s\n", 8N1); and the compile would flag this as an error because 'N' is not a number. however printf("Parity is %s\n", #PARITY); this would translate to printf("Pariry is %s\n", "8N1" and that is perfectly fine. ----
Jul 12, 2002 Thread starter #4 greadey Technical User Oct 25, 2001 231 GB luverly jubbly, thanks peeps greadey Upvote 0 Downvote