tech-kern archive

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

Re: KNF and the C preprocessor



On Mon, Dec 10, 2012 at 09:36:35AM -0600, David Young wrote:
> What do people think about setting stricter guidelines for using the
> C preprocessor than the guidelines from the past?  Example guidelines:
> 
> The C preprocessor MAY be used for
> 
> 1 Lazy evaluation: unlike a function call's arguments, a macro's
>   arguments are not evaluated before the macro is "called."  E.g., in
> 2 Lexical manipulation: e.g., concatenating symbols, converting symbols
>   to strings:
> 3 Generic programming:
> 4 Computed constants.  The result of a function call may not be used
>   in a case-statement, even if the function evaluates to a constant at
>   compile time.  You have to use a macro, instead.

Sure, these sound reasonable to me.  I don't see much in terms of guidelines
in /usr/share/misc/style, other than macro naming and avoiding side effects.

> The C preprocessor MUST NOT be used for
> 1 In-line code: 'static inline' subroutines are virtually always better
>   than macros.
> 2 Configuration management: use the compiler & linker to a greater
>   extent than the C preprocessor to configure your program for your
>   execution environment, your chosen compilation options, et cetera.
> 3 Virtually anything else. :-)

"MUST NOT" seems a bit strong, especially since I'm guessing there are
many existing cases of the preprocessor usage that violate this.
Do you have some concrete examples of the things you're trying to prevent?

eric


Home | Main Index | Thread Index | Old Index