What is the worst real-world macros/pre-processor abuse you've ever come across? What is the worst real-world macros/pre-processor abuse you've ever come across? c c

What is the worst real-world macros/pre-processor abuse you've ever come across?


From memory, it looked something like this:

#define RETURN(result) return (result);}int myfunction1(args) {    int x = 0;    // do something    RETURN(x)int myfunction2(args) {    int y = 0;    // do something    RETURN(y)int myfunction3(args) {    int z = 0;    // do something    RETURN(z)

Yes that's right, no closing braces in any of the functions. Syntax highlighting was a mess, so he used vi to edit (not vim, it has syntax coloring!)

He was a Russian programmer who had mostly worked in assembly language. He was fanatical about saving as many bytes as possible because he had previously worked on systems with very limited memory. "It was for satellite. Only very few byte, so we use each byte over for many things." (bit fiddling, reusing machine instruction bytes for their numeric values) When I tried to find out what kinds of satellites, I was only able to get "Orbiting satellite. For making to orbit."

He had two other quirks: A convex mirror mounted above his monitor "For knowing who is watching", and an occasional sudden exit from his chair to do a quick ten pushups. He explained this last one as "Compiler found error in code. This is punishment".


My worst:

#define InterlockedIncrement(x) (x)++#define InterlockedDecrement(x) (x)--

I spent two days of my life tracking down some multi-threaded COM ref-counting issue because some idiot put this in a header file. I won't mention the company I worked for at the time.

The moral of this story? If you don't understand something, read the documentation and learn about it. Don't just make it go away.


#define ever (;;)for ever {    ...}