We know #define statements are executed before the program is compiled (preprocessor directives) and so the characters used should have no other meaning (say keywords),but still the following statement is not possible and is erroneous why ?

#define int float

How many passes would the preprocessor directives run for as for the following type of statements,more than one pass would be required...

#define a b
#define b c
#define c a

Sort of confused right now...so thought of asking you guys...!!! Thanks in advance !!!

It seems it's your homework... See this forum rules... ;)
Some tips:
1. the scanner (lexical analyser) works "before" preprocessor so your 1st statement is wrong...
2. The C preprocessor is a one-pass text processor...

It seems it's your homework... See this forum rules... ;)
Some tips:
1. the scanner (lexical analyser) works "before" preprocessor so your 1st statement is wrong...
2. The C preprocessor is a one-pass text processor...

No buddy its not my homework and thanks to you moderators that I know how this community works and have great respects for it.

I searched for answers in http://c-faq.com and others too didn't find a satisfying answer so asking you guys to clear my own programming doubts.

#define is dealt with by preprocessor right and not lexixal analyser ?

And as preprocessor is a one pass text processor cyclic replacements is impossible right?

And my earlier query of why

#define int float

is still not clear...

I tested the following:

#include <stdio.h>

#define int float

int main(void)
{
        int foo = 1.12;

        printf("Foo: %f\n", foo);

        return 0;
}

Which resulted in the following:

jsomers@devlin04 test $ gcc define.c
define.c: In function `main':
define.c:6: warning: return type of `main' is not `int'
jsomers@devlin04 test $ ./a.out
Foo: 1.120000

So it seems to work here.

>And my earlier query of why

#define int float

>is still not clear...

You are substituting in your code, every word int for the word float.
That's all.
So, what happens when for example you write?

float main(void)

It doesn't work properly, correct? Because main should return an int.

Thanks everyone i was misguided by my own doubts.... ;) Thanks for helping.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.