By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,111 Members | 1,665 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,111 IT Pros & Developers. It's quick & easy.

Need help on Macro

P: n/a
Hi All,

I need to define a macro as follows

#define VERSION "1.0"
#ifdef (VERSION == "1.0")
#endif

main() {
}
I want to check the Version using macro . But the code compilation
gives error " macro names must be identifiers"
I know that #ifdef will work only for integers . Also I need this to
be done before main.
Need help for the same.

Regards,
Khan.

Mar 5 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
za*******@gmail.com wrote:
Hi All,

I need to define a macro as follows

#define VERSION "1.0"
#ifdef (VERSION == "1.0")
#endif

main() {
}
I want to check the Version using macro . But the code compilation
gives error " macro names must be identifiers"
I know that #ifdef will work only for integers . Also I need this to
be done before main.
Need help for the same.
Try:

#define VERSION 1
#if VERSION == 1
/* ... */
#endif
int main(void) { /* ... */ return 0; }

Mar 5 '07 #2

P: n/a
On Mar 5, 3:56 pm, "santosh" <santosh....@gmail.comwrote:
zaheer...@gmail.com wrote:
Hi All,
I need to define a macro as follows
#define VERSION "1.0"
#ifdef (VERSION == "1.0")
#endif
main() {
}
I want to check the Version using macro . But the code compilation
gives error " macro names must be identifiers"
I know that #ifdef will work only for integers . Also I need this to
be done before main.
Need help for the same.

Try:

#define VERSION 1
#if VERSION == 1
/* ... */
#endif
int main(void) { /* ... */ return 0; }- Hide quoted text -

- Show quoted text -
I want to compare the different version like "1.1" "1.2" etc. But
these are not integers and the macro will not accept them.
So how do I compare the non integer values

Mar 5 '07 #3

P: n/a

za*******@gmail.com wrote:
On Mar 5, 3:56 pm, "santosh" <santosh....@gmail.comwrote:
zaheer...@gmail.com wrote:
Hi All,
I need to define a macro as follows
#define VERSION "1.0"
#ifdef (VERSION == "1.0")
#endif
main() {
}
I want to check the Version using macro . But the code compilation
gives error " macro names must be identifiers"
I know that #ifdef will work only for integers . Also I need this to
be done before main.
Need help for the same.
Try:

#define VERSION 1
#if VERSION == 1
/* ... */
#endif
int main(void) { /* ... */ return 0; }- Hide quoted text -

- Show quoted text -

I want to compare the different version like "1.1" "1.2" etc. But
these are not integers and the macro will not accept them.
So how do I compare the non integer values
The constant expression following an #if or #elif directive must
evaluate to an integral value. So, you can't do what you're asking.
Convert the version numbers into integer format. For example 1.1 will
be 11, 1.2 will be 12, 1.56 will be 156 etcetera.. Then you can write
the #if directive as I've shown earlier.

Mar 5 '07 #4

P: n/a
On 5 Mar, 11:22, "zaheer...@gmail.com" <zaheer...@gmail.comwrote:
On Mar 5, 3:56 pm, "santosh" <santosh....@gmail.comwrote:
zaheer...@gmail.com wrote:
Hi All,
I need to define a macro as follows
#define VERSION "1.0"
#ifdef (VERSION == "1.0")
#endif
main() {
}
I want to check the Version using macro . But the code compilation
gives error " macro names must be identifiers"
I know that #ifdef will work only for integers . Also I need this to
be done before main.
Need help for the same.
Try:
#define VERSION 1
#if VERSION == 1
/* ... */
#endif
int main(void) { /* ... */ return 0; }- Hide quoted text -
- Show quoted text -

I want to compare the different version like "1.1" "1.2" etc. But
these are not integers and the macro will not accept them.
So how do I compare the non integer values
Recognize that you are not talking about a single version number, but
2 - a major and a minor version number. Specify them as different
symbols and work from there.

Mar 5 '07 #5

P: n/a
santosh wrote, On 05/03/07 11:34:
za*******@gmail.com wrote:
>On Mar 5, 3:56 pm, "santosh" <santosh....@gmail.comwrote:
>>zaheer...@gmail.com wrote:
Hi All,
I need to define a macro as follows
#define VERSION "1.0"
#ifdef (VERSION == "1.0")
#endif
main() {
}
I want to check the Version using macro . But the code compilation
gives error " macro names must be identifiers"
I know that #ifdef will work only for integers . Also I need this to
be done before main.
Need help for the same.
Try:

#define VERSION 1
#if VERSION == 1
/* ... */
#endif
int main(void) { /* ... */ return 0; }- Hide quoted text -

- Show quoted text -
I want to compare the different version like "1.1" "1.2" etc. But
these are not integers and the macro will not accept them.
So how do I compare the non integer values

The constant expression following an #if or #elif directive must
evaluate to an integral value. So, you can't do what you're asking.
Convert the version numbers into integer format. For example 1.1 will
be 11, 1.2 will be 12, 1.56 will be 156 etcetera.. Then you can write
the #if directive as I've shown earlier.
Horrible. If you also do things with the version at run time version 1.2
will appear to be a long way before version 1.56. Yes, I do have code
comparing versions!

As mark_bluemel said, split the version in to separate identifiers for
major and minor. You can always use some preprocessor magic to stick
them back together as 1.56 when you need/want that.
--
Flash Gordon
Mar 5 '07 #6

P: n/a
On Mar 5, 11:22 am, "zaheer...@gmail.com" <zaheer...@gmail.comwrote:
I want to compare the different version like "1.1" "1.2" etc. But
these are not integers and the macro will not accept them.
So how do I compare the non integer values
#define VERSION_1_0 10000
#define VERSION_1_0_1 10001
#define VERSION_2_1_0 20100

#define VERSION VERSION_1_0_1

#if VERSION >= VERSION_1_0_1 && VERSION <= VERSION_2_1_0 || VERSION ==
VERSION_1_0
.... Things for version 1.0.1 to 2.1.0 or version 1.0
#endif
Mar 5 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.