Hi All, I am being confused with the use of enum vs #define. Sometold me that enum is better and some #define. Well, as per my understanding while defining sequencial data i.e. 1,2,3,4... at that time enum is better as one doesn't has to write the number i.e enum Month { Jan, Feb, .... Dec }; But in case of random number defination, #define will be good. i.e #define TEMPERATURE 35 #define USL 45 #define LSL 25 Which one is good with respect to memory ? What are the advantages/disadvantages of both.
Keil C51 always uses 8 bits if it can: http://www.keil.com/support/man/docs/c51/c51_ap_datastorage.htm This must have happened when I left Keil for a good while and did not get update notes, it used to be standard C (always an int). Note; I did not "leave" Keil for any other reason than using a "non-Keil" processor, the XA, in combination with the '51 and running 2 different toolsets is, in my book, a no-no if avoidable. "I can not afford the extra byte of data space." enum per se uses no data space. this was in reference to the "forced" int. Erik
"it used to be standard C (always an int)." Yes - standard 'C' says "always int" But, like Drew, every compiler I've ever used has the option to store enums in the smallest space possible - including PC compilers! "this was in reference to the "forced" int." No - that's irrelevant. enums themselves do not use data space - they're just compile-time symbols for numeric values. As immediate operands they (and numeric literals, and #defined constants) would end up in code - not data - space!
"this was in reference to the "forced" int." No - that's irrelevant. enums themselves do not use data space - they're just compile-time symbols for numeric values. OK, we do not understand each other, so let me try again. Enum does not, in itself take any space, but in implementations that adhere to standard C making the enumerated variable an int, they do cost you one byte, if you otherwise would have used a char. Erik