[PATCH 5/6] net: tftp: use IS_ENABLED(CONFIG_NET_TFTP_VARS) instead of #if

Rasmus Villemoes rasmus.villemoes at prevas.dk
Mon Oct 17 08:18:51 CEST 2022


On 16/10/2022 20.28, Ramon Fried wrote:
> On Fri, Oct 14, 2022 at 8:44 PM Rasmus Villemoes
> <rasmus.villemoes at prevas.dk> wrote:
>>
>> Nothing inside this block depends on NET_TFTP_VARS to be set to parse
>> correctly. Switch to C if() in preparation for adding code before
>> this (to avoid a declaration-after-statement warning).
> What's the motivation here ? The #ifdef is supposed to allow smaller
> code size if feature is not used.

And as always with these types of conversions, nothing changes in that
regard - an "if (0)" is optimized out by the compiler just fine.

The motivation is in the commit message: The following patch will need
to add a bit of logic at the very beginning of the function, so if I
left the #ifdef block as-is, the declaration of the ep variable would
lead to a declaration-after-statement warning; lifting the declaration
to the top would either require repeating the ugly ifdeffery, or give a
"variable not used" warning.

It's also in general the preferred method, because it means the
contained code gets checked for syntactic correctness regardless of
.config - but that very same thing is also why it cannot be applied
universally, if the contained code e.g. refers to struct fields that are
only defined with certain CONFIG_FOO set [and this also was alluded to
in the commit message].

Rasmus


More information about the U-Boot mailing list