Is this some kind of optimization? if (1) {...} else (void) 0

Possible duplicate:
Why do meaningless do / while and if / else statements sometimes exist in C / C ++ macros?

In the OpenJDK source code, I found this macro:

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

Used as you would expect, for example:

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 guess this is some kind of optimization thing. Can someone explain or provide a link? This is hard for Google.

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

+3
source share

Source: https://habr.com/ru/post/1765631/


All Articles