Is your code bugged in the following case?
printf(" /*This is not a comment but removing me changes program behaviour*/");
This one more weird
if( match("/*")){
doMagicStuff();
}
else
match("*/");
You can incurr the risk of it becoming reduced to
if( match("")); //compilationcode errorthat compile fine and have unpredictable side effects
You have to write a complete parser (a simple one, but too complex for becoming a single answer) to avoid these issues.
You can know if you have done everything correctly luckily:
- Compile the kernel ==> binaries A
- Strip comments
- Compile the kernel ==> binaries B
- If binaries A and B are not the same, then your comment remover has some bug.