#define and data types
-
Stupid question, perhaps, but.... If I were to want to use #define to define a set of characters/string instead of a number, is there anything particular I have to go through it? In other words, I'm going to be using a specific set of strings to begin and end a number of strings I am concatenating, and I figured that using #define would be the best way to go. However, I've only used #define for numbers before, and I wasn't sure if #define could even use other types, or for that matter if typecasting was necessary. I was starting to write: #define xmlBeginStatement "<" //plus other stuff and then wondered if I had to do either: #define xmlBeginStatement char "<" or something else like that. And my darned reference manuals say nothing about it. :( Thanks! James A Beggs Microsoft MSN Mobile Component Test Team
-
Stupid question, perhaps, but.... If I were to want to use #define to define a set of characters/string instead of a number, is there anything particular I have to go through it? In other words, I'm going to be using a specific set of strings to begin and end a number of strings I am concatenating, and I figured that using #define would be the best way to go. However, I've only used #define for numbers before, and I wasn't sure if #define could even use other types, or for that matter if typecasting was necessary. I was starting to write: #define xmlBeginStatement "<" //plus other stuff and then wondered if I had to do either: #define xmlBeginStatement char "<" or something else like that. And my darned reference manuals say nothing about it. :( Thanks! James A Beggs Microsoft MSN Mobile Component Test Team
#define is a preprocessor job, it simply defines text to replace in source code before it's passed to compiler. It does know nothing about types. Pavel Sonork 100.15206
-
#define is a preprocessor job, it simply defines text to replace in source code before it's passed to compiler. It does know nothing about types. Pavel Sonork 100.15206
Yeah! He's right. This code:
#define XXX void function(int r)
static XXX
{}
will be seen by the comiler as:
static void function(int r)
{}
You can write anything after #define
Ñ There is only one MP Ð
-
Stupid question, perhaps, but.... If I were to want to use #define to define a set of characters/string instead of a number, is there anything particular I have to go through it? In other words, I'm going to be using a specific set of strings to begin and end a number of strings I am concatenating, and I figured that using #define would be the best way to go. However, I've only used #define for numbers before, and I wasn't sure if #define could even use other types, or for that matter if typecasting was necessary. I was starting to write: #define xmlBeginStatement "<" //plus other stuff and then wondered if I had to do either: #define xmlBeginStatement char "<" or something else like that. And my darned reference manuals say nothing about it. :( Thanks! James A Beggs Microsoft MSN Mobile Component Test Team
why not consider: const char xmlBeginStatement[] = "<"; some would consider it be be 'better form'....... Just trying to keep the forces of entropy at bay
-
why not consider: const char xmlBeginStatement[] = "<"; some would consider it be be 'better form'....... Just trying to keep the forces of entropy at bay
I did. I had decided on using defines at the time. I'm certainly not married to it, however.
-
I did. I had decided on using defines at the time. I'm certainly not married to it, however.
Meyer's will argue that using const definitions over #define is the way to go...I agree with him.... Just trying to keep the forces of entropy at bay