Need help on Macro

Z

zaheer031

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.
 
S

santosh

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; }
 
Z

zaheer031

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
 
S

santosh

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.
 
M

mark_bluemel

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.
 
F

Flash Gordon

santosh wrote, On 05/03/07 11:34:
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.
 
C

christian.bau

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,792
Messages
2,569,639
Members
45,353
Latest member
RogerDoger

Latest Threads

Top