Compile time (C/C++)

sonxEr77

Expert Member
Joined
Oct 22, 2006
Messages
1,809
Reaction score
0
Location
around
Hi gurus.. just wondering if white spaces (ASCII space, tab, & form feed character) are ignored at compile time
 
yes and no

there needs to be a space after a reserved word.
int i=10 can't be written as inti=10 for example;

but other than that, no restrictions (as far as i remember).

- twiga
 
yes and no

there needs to be a space after a reserved word.
int i=10 can't be written as inti=10 for example;

but other than that, no restrictions (as far as i remember).

- twiga

Your example then does not leave a clear answer or absolute answer. In fact, to me it suggests that spaces are not ignored at compile time since if left at some places the compile would complain. Is it far to say so?
 
In fact, to me it suggests that spaces are not ignored at compile time since if left at some places the compile would complain. Is it far to say so?

Yes (sorry if my answer was vague).
 
Well the thing is the compiler goes through a couple of phases tokenizing is one, and that basically takes out all the important stuff like keywords and variables, so if you put in: int i = 10; int,i,=,10 will be tokenized but if: inti=10 inti,=,10 will be but: int \t i\t\s = \t 10 would still produce int,i,=,10.

where \t = tab and \s = space.
The thing is compiler construction is a field on its own there are many things to consider, like grammars and lexing etc, if you really want to get to know all of this, start to code! and google compiler construction :) but even seasoned coders don't know what goes on under the hood.
 
Last edited:
Out of curiosity, why do you ask?

Busy compiling a nice C quiz. Thought wud be a nice question to ask. But seems a little complex now isn't it? Fact is, a programmer shouldn't worry much about white spaces as far as compilation is concerned.

i.e: int /space i; or int /tab i; or
int /new line
i;

..... should not make any difference.. in my example i've used three white spaces : 1. A space , 2. A tab, and 3. a form feed/newline character (enter)

Thus C will compile with no complains.... SORRY i had to type /space, /tab, /new line cause this editor (MyADSL) does not allow spaces and tab, mhh... similar issue with C compiler maybe!
 
Last edited:
There's always something new to learn... Check this code

#define INDX(x) (++indx[x][ptr[x-1]],&indx[x][ptr[x-1]])

int main()
{
int indx[6]={0,1,2,3,4,5};
int i=10;

char arr[][20]={"%hs'nt %s %s","%dbool", "?n%shis? ",};
char *ptr[3];

ptr[0]=&arr[0][0];
ptr[1]=&arr[1][0];
ptr[2]=&arr[2][0];

printf(INDX(1),INDX(3),INDX(2));

}

Anything strange?
 
Top
Sign up to the MyBroadband newsletter
X