6

If I declare the variable like

int a/*comment*/ ; //This does not give any error .
int a/*comment*/bc; This gives error

Now I am not getting the reason behind this , According to me when the character a is read for the first time after that symbol / is read so is it that it switches to some other state of DFA for recognizing some other pattern hence no error while in the second case after comment is read it finds some other sequence which couldn't belong to the formal pattern hence it gets halted in some non-final state of finite automaton due to which it gives an error .

Please clear this confusion .

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
Radha Gogia
  • 765
  • 1
  • 11
  • 22
  • Perhaps the parser fails due to massive lack or misplacement of commas ...? ;-) – alk Dec 06 '15 at 15:13

3 Answers3

6

C11 standard section 5.1.1.2 "Translation phases", phase 3:

...Each comment is replaced by one space character. ...

Comments are replaced during (well, just before) the preprocessing phase of C compilation. This is before "real" parsing occurs. Comments are therefore considered equivalent to whitespace in the main part of the C language.

Community
  • 1
  • 1
Alex Celeste
  • 12,824
  • 10
  • 46
  • 89
6

According to the C Standard (5.1.1.2 Translation phases)

3. ...Each comment is replaced by one space character. 

Thus this line

int a/*comment*/bc; 

after the translation phase is equivalent to

int a bc; 

But you could write :)

int a\
bc; 

provided that bc; starts at the first position of the next line.

Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335
5

During preprocessing comments are replaced with a single whitespace.

Your code becomes:

int a bc;
Karoly Horvath
  • 94,607
  • 11
  • 117
  • 176