On 29/05/2016, Daniel Gimpelevich <daniel@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote: > On Sat, 2016-05-28 at 12:05 -0700, Daniel Gimpelevich wrote: >> On Sat, 2016-05-28 at 13:31 +0300, Antony Pavlov wrote: >> > Can we use 'if' instead of preprocessor's '#if' here? >> > >> > If we use regular C 'if' operator with IS_ENABLED() instead of >> > '#if/#ifdef' >> > then the compiler can check all the code. >> > >> > E.g. please see this barebox patch: >> > >> > >> > http://lists.infradead.org/pipermail/barebox/2014-February/017834.html >> >> Sigh. I guess I will resubmit again… > > Upon further review, no, we cannot use 'if' instead of '#if' here. The > reference to the appended DTB would throw a linker error if the option > to put it there is not enabled. Sorry. Please note that modern gcc ignores 'undefined reference' errors inside optimized out code block (e.g. 'if (0) { ... }'). Here is an example: $ echo <<EOF; > esymbol.c int main() { if (CONFIG_ESYMBOL_STUFF) { extern int esymbol; esymbol = 1; } } EOF $ gcc -DCONFIG_ESYMBOL_STUFF=1 esymbol.c /tmp/ccNCGFCS.o: In function `main': esymbol.c:(.text+0x6): undefined reference to `esymbol' collect2: error: ld returned 1 exit status $ gcc -DCONFIG_ESYMBOL_STUFF=0 esymbol.c $ echo $? 0 $ $ gcc --version gcc (Debian 4.9.3-12) 4.9.3 Copyright (C) 2015 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -- Best regards, Antony Pavlov