'Why does the preprocessor replace comments by single space instead of removing them in C language [closed]
I've read that comments in C language are replaced by single spaces while pre-processing. In the specification
The program is split into tokens separated by white-space characters; comments are replaced by a single space[emphasis added]. Then preprocessing directives are obeyed, and macros (Pars.A.12.3-A.12.10) are expanded.
Is there a specific reason behind this choice?
I've seen this example
#include <stdio.h>
int/*This is a comment*/main(){
return 0;
}
If we don't replace the comment with a single space the above would raise errors. However, it appears a bad practice to write comments in this manner. Is there any other reason why replacing a comment with a single space instead of just striping it is helpful?
Solution 1:[1]
int a/* comment */b;
If it weren't replaced by a space the above would compile as int ab;. I would argue this would be worse than the current specs.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | bolov |
