G
G G
#include <stdio.h> // for printf()
int main (void)
{
#define FNORD hello
int FNORD = 23;
printf ("hello, your number today is %d\n", hello);
#define NOBODY_HOME
static unsigned NOBODY_HOME int thing = 42;
printf ("thing, your number today is %d\n", thing);
// This is actually a dangerous way to do this. See
// the section about macro hygiene.
#define SUM(x, y) x + y
int value = SUM(23, 42);
printf ("value, your number today is %d\n", value);
return 0;
} // main
This code comes from, Advanced Mac OS Programming.
I understand the author is trying to demonstrate the preprocessor expansion but
this would not really be done would it.
for example :
#define FNORD hello
int FNORD = 23;
printf ("hello, your number today is %d\n", hello);
is this unusual or should i expect to see a lot of this method, style, in processor
code. (leaning c now) in this example, i'm talking about defining FNORD to hello
then assigning 23 to FNORD. so far, and my experience is limited, i have only
seen #define to replace text, or some type of macro definition. i have seen
an assignment allowed in the program, as done here.
Thanks,
g.
int main (void)
{
#define FNORD hello
int FNORD = 23;
printf ("hello, your number today is %d\n", hello);
#define NOBODY_HOME
static unsigned NOBODY_HOME int thing = 42;
printf ("thing, your number today is %d\n", thing);
// This is actually a dangerous way to do this. See
// the section about macro hygiene.
#define SUM(x, y) x + y
int value = SUM(23, 42);
printf ("value, your number today is %d\n", value);
return 0;
} // main
This code comes from, Advanced Mac OS Programming.
I understand the author is trying to demonstrate the preprocessor expansion but
this would not really be done would it.
for example :
#define FNORD hello
int FNORD = 23;
printf ("hello, your number today is %d\n", hello);
is this unusual or should i expect to see a lot of this method, style, in processor
code. (leaning c now) in this example, i'm talking about defining FNORD to hello
then assigning 23 to FNORD. so far, and my experience is limited, i have only
seen #define to replace text, or some type of macro definition. i have seen
an assignment allowed in the program, as done here.
Thanks,
g.