Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Except that text inside #if 0 still has to lex correctly.

Are you sure? I just tried on godbolt and that’s not true with gcc 14.2. I’ve definitely put syntax errors intentionally into #if 0 blocks and had it compile. Are you thinking of some older version or something? I thought the pre-processor ran before the lexer since always…



There are three (relevant) phases (see “translation phases” in section 5 of the standard):

• program is lexed into preprocessing tokens; comments turn into whitespace

• preprocessor does its thing

• preprocessor tokens are turned into proper tokens; different kinds of number are disambiguated; keywords and identifiers are disambiguated

If you put an unclosed comment inside #if 0 then it won’t work as you might expect.


Ah, I see. You’re right!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: