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

Wouldn't it be wise if the compiler (or preprocessor) issued at least a warning if you redefine language keywords ? :)

So I just pasted this into a C++ file I was working on and it compiled without a single warning:

#define struct union

#define if while

#define else

#define break

#define double float

#define volatile // this one is cool

I mean, redefining language keywords is not a thing I do every day and I guess most of you don't do it either and I can't see a valid reason why you'd want to do it in a normal project. For people who really want to do it, they'd just disable the warning.

Am I missing something here ?



No warnings is the whole point.

My c++ isn't so good that I understand that first one, but if->while and break->"" can introduce infinite loops, else->"" will break logic (and possibly hit null pointers), double->float will cause subtle rounding errors in numeric computation, and volatile->"" will break multi-threaded apps unpredictably.

It's evil, subtle code breakage that because of the macro (in an included header far far away) leave the code looking perfectly ordinary.




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

Search: