3

Possible Duplicate:
Why are there sometimes meaningless do/while and if/else statements in C/C++ macros?

In the source code of OpenJDK I found this macro:

#define PUTPROP(props, key, val) \
    if (1) { \
    // some code
    } else ((void) 0)

It is used as one would expect, e.g.:

PUTPROP(props, "os.arch", sprops->os_arch);

(If you are interested, it is in the file jdk/src/share/native/java/lang/System.c)

I suppose this is some kind of optimization thing. Can somebody explain or provide a link? This is hard to google.

And before someone asks: Yes, I'm just curious.

Community
  • 1
  • 1
musiKk
  • 14,751
  • 4
  • 55
  • 82
  • 5
    Duplicate of [Why are there sometimes meaningless do/while and if/else statements in C/C++ macros? ](http://stackoverflow.com/questions/154136/why-are-there-sometimes-meaningless-do-while-and-if-else-statements-in-c-c-macr) – James McNellis Sep 20 '10 at 14:01

0 Answers0