Preprocessor: how to define a macro in terms of another

R

recvfrom

Hi!

I have a need to define a macro to be the larger (integer comparison)
of two other
macros, already defined in system header files. Is this possible??
Thanks!!!

-r
 
A

A. Sinan Unur

I have a need to define a macro to be the larger (integer comparison)
of two other macros, already defined in system header files. Is this
possible??

I would have tried the obvious before asking:

#include <stdio.h>

#define VAL1 10
#define VAL2 20

#if VAL1 > VAL2
#define VAL_MAX VAL1
#else
#define VAL_MAX VAL2
#endif

int main(void) {
printf("%d\n", VAL_MAX);
return 0;
}

/* EOF */

D:\Home\asu1\UseNet\clc> gcc -Wall -W t.c -o t.exe -ansi -pedantic

D:\Home\asu1\UseNet\clc> t
20

I am assuming this is standards compliant, and hope someone will correct
me if it isn't.

Sinan
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top