Hacker News new | ask | show | jobs
by hairy_man674 3530 days ago
Any preprocessor definition that changes the language like that example makes C programmers rage. As a rule, typedef and macros and friends should be avoided for clarity and debugging (opinion). An actual example of this: The programmer who created Bourne Shell, at Bell Labs in 1970s, intentionally did this to make C more like Algol. I think BSD still uses some of the original code. Understandably, not everyone liked the idea.
2 comments

What's the problem with typedef? It just names a new type rather than making things work differently than you'd expect.
The main misuse, again this is opinion based, is that it hides (obscures) the type of variable. If you have (say) a very large struct containing several member variables and functions, a programmer can be misled into returning it from a function or declaring it on the stack.

Of course there are reasonable uses for it. Contrary, to the above you might use it to intentionally make an object opaque as a way of abstracting its details from users or when declaring use of int/long in code.

Legit usage: #define private public #include "some old thing I need the internals of but can't change.h"
There's at least one compiler that adds visibility into the name mangling (is it gcc? Seems like the kind of thing they'd do), so if you unhide functions in this way you still won't necessarily be able to call them.

(The compiler is also free to change the object layout when you do this, too, though I've no idea whether any of them do.)

> Seems like the kind of thing they'd do

Forced to do by Microsoft C and C++ that mangle names.

C has no such keywords. Why the need for this hackery? Curious also if putting that in a header and including it in a C++ program even compiles without leading to undefined behaviour...