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 07:37:14PM +0000, David Laight wrote:
> 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:
> ...
> > 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.
>
> The alternative to constants would be C enums.
> However C enums are such 2nd class citizens that they have problems
> of their own.
Explicit enums are a little better, no? And they do make things a lot
more obvious when debugging.
>
> > The C preprocessor MUST NOT be used for
> >
> > 1 In-line code: 'static inline' subroutines are virtually always better
> > than macros.
>
> That rather depends on your definition of better.
> a) #define macros tend to get optimised better.
Can you provide an example, with a compiler currently used by our tree?
> b) __LINE__ (etc) have the value of the use, not the definition.
Yes, but if you use static inlines, the debugger's got both -- which
it won't, if you use macros...
Thor
Home |
Main Index |
Thread Index |
Old Index