Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 7 Aug 2000 12:20:03 -0700 (PDT)
From:      Bruce Evans <bde@zeta.org.au>
To:        freebsd-bugs@FreeBSD.org
Subject:   Re: kern/9869: Addition to style(9) about usage of macro.
Message-ID:  <200008071920.MAA88543@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR kern/9869; it has been noted by GNATS.

From: Bruce Evans <bde@zeta.org.au>
To: Johan Karlsson <k@numeri.campus.luth.se>
Cc: FreeBSD-gnats-submit@FreeBSD.ORG, bde@FreeBSD.ORG
Subject: Re: kern/9869: Addition to style(9) about usage of macro.
Date: Tue, 8 Aug 2000 05:10:18 +1000 (EST)

 On Mon, 7 Aug 2000, Johan Karlsson wrote:
 
 > Regarding MACRO in style(9) 
 > (see http://www.FreeBSD.org/cgi/query-pr.cgi?pr=9869)
 > 
 > This is what the manpage says currently about MACRO:s
 > ===============
 >      Macros are capitalized, parenthesized, and should avoid side-effects.
 >      Put a single tab character between the `#define' and the macro name.  If
 >      they are an inline expansion of a function, the function is defined all
 >      in lowercase, the macro has the same name all in uppercase.  If the macro
 >      needs more than a single line, use braces (`{' and `}'). Right-justify
 >      the backslashes; it makes it easier to read.  If the macro encapsulates a
 >      compound statement, enclose it in a ``do'' loop, so that it can safely be
 >      used in ``if'' statements.  Any final statement-terminating semicolon
 >      should be supplied by the macro invocation rather than the macro, to make
 >      parsing easier for pretty-printers and editors.
 > 
 >      #define MACRO(x, y) do {                                                \
 >              variable = (x) + (y);                                           \
 >              (y) += 2;                                                       \
 >      } while(0)
 > ===============
 > 
 > Do you think that is enough or should it say anything more?
 
 Parts of it are poorly worded, especially "it makes it easier to read".
 
 I made the following changes locally a long time ago:
 
 diff -c2 style.9~ style.9
 *** style.9~	Sun Jul 23 00:50:21 2000
 --- style.9	Tue Aug  8 04:53:58 2000
 ***************
 *** 86,95 ****
   .Ed
   .Pp
 ! Macros are capitalized, parenthesized, and should avoid side-effects.
   Put a single tab character between the 
   .Ql #define
   and the macro name.  
 ! If they are an inline expansion of a function, the function is defined
 ! all in lowercase, the macro has the same name all in uppercase.  If the
   macro needs more than a single line, use braces
   .Po
 --- 128,150 ----
   .Ed
   .Pp
 ! Do not #define or declare names in the implementation namespace except
 ! for implementing application interfaces.
 ! .Pp
 ! The names of
 ! .Dq Li unsafe
 ! macros (ones that have side effects), and the names of macros for
 ! manifest constants, are all in uppercase.
 ! The expansions of expression-like macros are either a single token
 ! or have outer parentheses.
   Put a single tab character between the 
   .Ql #define
   and the macro name.  
 ! If a macro is an inline expansion of a function, the function name is
 ! all in lowercase and the macro has the same name all in uppercase.
 ! .\" XXX the above conflicts with ANSI style where the names are the
 ! .\" same and you #undef the macro (if any) to get the function.
 ! .\" It is not followed for MALLOC(), and not very common if inline
 ! .\" functions are used.
 ! If a
   macro needs more than a single line, use braces
   .Po
 
 > If it is enough, I think this PR 9869 can be closed.
 
 The PR really asks for a semicolon to be added to most invocations of
 SYSINIT().  This would currently add lots of pedantic syntax errors.
 The hint in the man page about using "do ... while (0)" doesn't apply
 because SYSINIT() is a declaration, not a statement.  My "struct __hack"
 hack (menioned in the PR followup) can be used.
 
 Bruce
 
 


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200008071920.MAA88543>