RE: Conding style question regarding configuration

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> > Quick question regarding how to configure out code depending on a
> CONFIG_xxx
> > switch. As far as I understood so far, the proper way to do this is
> not by
> > doing an #ifdef but by using a regular if with IS_ENABLED like so:
> >
> > if (IS_ENABLED(CONFIG_PCI)) {
> > }
> >
> > Such that the compiler can still check the code even if the switch is
> > disabled. Now that all works fine and dandy for statements within a
> > function, but how do you configure out, say, global variable
> definitions
> > referencing types that are tied to this configuration switch? Or
> should
> > I just leave them in, depending on the compiler to optimize them away?
> >
> > Obviously the code depends on those variables again, so if it's not
> > done consistently the compiler will complain somehow if the switch is
> not
> > defined ...
> >
> > Also, with if (IS_ENABLED()) I cannot remove my function prototypes,
> > just the function body. Is that really how it's supposed to be done?
> >
> 
> Yes. Code and data with static linkage will just be optimized away by
> the compiler if the CONFIG_xx option is not enabled, so all you need
> to guard are the actual statements, function calls etc.
>
Ok, makes sense. Then I'll just config out the relevant function bodies
and assume the compiler will do the rest ...

Thanks,
Pascal van Leeuwen
Silicon IP Architect, Multi-Protocol Engines @ Inside Secure
www.insidesecure.com







[Index of Archives]     [Kernel]     [Gnu Classpath]     [Gnu Crypto]     [DM Crypt]     [Netfilter]     [Bugtraq]

  Powered by Linux