> From: Michael Richardson <m...@sandelman.ca>
> Sent: Thursday, 31 March, 2022 14:18
> 
> Michael Wojcik <michael.woj...@microfocus.com> wrote:
>     > #if defined OPENSSL_SYS_WINDOWS
>     > # include <shared/netiodef.h>
>     > #else
>     > # include <netinet/ip6.h>
>     > #endif
> 
> But, don't all the OPENSSL_* macros expand to 0/1, anyway, so we actually
> just want #if OPENSSL_SYS_WINDOWS?

I did a quick grep through the source for 1.1.1k (just because that's what I 
had to hand; we've actually just finished updating my portfolio to 1.1.1n), and 
there's a mix of #if OPENSSL_SYS_WINDOWS and #if defined(OPENSSL_SYS_WINDOWS). 
apps/s_client.c uses the latter, for example.

Actually, in the context of #if expressions, unrecognized tokens expand to 0 
anyway:

        After all replacements due to macro expansion and the defined unary
        operator have been performed, all remaining identifiers are replaced
        with the pp-number 0...

(ISO 9899:1999 6.10.1 #3)

So defining a macro used for conditional inclusion to the value 0 is kind of a 
bad idea, since that means there's different behavior between #if FOO and #if 
defined FOO. Much better to not define it and get the default value of 0 if you 
want to turn it off.

But that said, #if OPENSSL_SYS_WINDOWS is safer for the same reason: it doesn't 
matter whether it's defined as 0, or not defined at all.

The "defined" operator is overused in C source generally. It's good for things 
like header inclusion guards. It's not really a good choice for most other 
cases of conditional inclusion.

-- 
Michael Wojcik

Reply via email to