From shigio@wafu.netgate.net  Mon Feb  1 16:43:16 1999
Received: from wafu.netgate.net (wafu.netgate.net [204.145.147.80])
          by hub.freebsd.org (8.8.8/8.8.8) with SMTP id QAA14362
          for <FreeBSD-gnats-submit@freebsd.org>; Mon, 1 Feb 1999 16:43:13 -0800 (PST)
          (envelope-from shigio@wafu.netgate.net)
Received: (qmail 7543 invoked from network); 1 Feb 1999 16:34:13 -0000
Received: from ins17.tama-ap3.dti.ne.jp (HELO choota.signet.or.jp) (203.181.67.17)
  by wafu.netgate.net with SMTP; 1 Feb 1999 16:34:13 -0000
Received: (from shigio@localhost) by choota.signet.or.jp (8.8.7/) id JAA07129; Tue, 2 Feb 1999 09:47:43 +0900 (JST)
Message-Id: <199902020047.JAA07129@choota.signet.or.jp>
Date: Tue, 2 Feb 1999 09:47:43 +0900 (JST)
From: shigio@wafu.netgate.net
Reply-To: shigio@wafu.netgate.net
To: FreeBSD-gnats-submit@freebsd.org
Subject: Addition to style(9) about usage of macro.
X-Send-Pr-Version: 3.2

>Number:         9869
>Category:       kern
>Synopsis:       When using macros out of function, they should end with a semicolon.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon Feb  1 16:50:00 PST 1999
>Closed-Date:    Fri Dec 29 20:20:53 GMT 2006
>Last-Modified:  Fri Dec 29 20:20:53 GMT 2006
>Originator:     Shigio Yamaguchi
>Release:        All release
>Organization:
>Environment:

	All environment.

>Description:

	The following statement should be added to style(9).

	     When using macros out of function, they should end with a semicolon.

	     SYSINIT(placeholder, SI_SUB_DUMMY,SI_ORDER_ANY, NULL, NULL);

	Otherwise, ctags(1) and gtags(1) cannot recognize function definitions
	collectly.

>How-To-Repeat:

	non

>Fix:
	
	non
>Release-Note:
>Audit-Trail:

From: Bruce Evans <bde@zeta.org.au>
To: FreeBSD-gnats-submit@FreeBSD.ORG, shigio@wafu.netgate.net
Cc:  
Subject: Re: kern/9869: Addition to style(9) about usage of macro.
Date: Tue, 2 Feb 1999 15:21:56 +1100

 >	The following statement should be added to style(9).
 >
 >	     When using macros out of function, they should end with a semicolon.
 >
 >	     SYSINIT(placeholder, SI_SUB_DUMMY,SI_ORDER_ANY, NULL, NULL);
 >
 >	Otherwise, ctags(1) and gtags(1) cannot recognize function definitions
 >	collectly.
 
 Unfortunately, a semicolon after SYSINIT() is a (pedantic) syntax error.
 
 I don't think there should be a style rule about this.  Instead, there
 should be rules about writing statement macros and declaration macros
 more carefully so that not having the semicolon is a (non-pedantic)
 syntax error.  The usual method for statement macros is to wrap the
 macro in `do ... while (0)', and a not so usual method for declaration
 macros is to end the macro with `struct __hack'.
 
 Bruce

From: Johan Karlsson <k@numeri.campus.luth.se>
To: FreeBSD-gnats-submit@FreeBSD.ORG
Cc: bde@FreeBSD.ORG
Subject: Re: kern/9869: Addition to style(9) about usage of macro.
Date: Mon, 07 Aug 2000 20:09:53 +0200

 Hi Bruce
 
 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?
 
 If it is enough, I think this PR 9869 can be closed.
 
 
 Thanks
 Johan K
 

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
 
 

From: Sheldon Hearn <sheldonh@uunet.co.za>
To: freebsd-gnats-submit@FreeBSD.org
Cc:  
Subject: Re: kern/9869: Addition to style(9) about usage of macro. 
Date: Tue, 08 Aug 2000 11:58:24 +0200

 Bruce Evans' patch has been committed to the style(9) page.  I'm not
 sure that we can go much further with this PR without burning our feet
 on holy ground.
 
 Can you think of anything more we can do to improve the status quo, or
 are you happy for this PR to be closed?
 
 Ciao,
 Sheldon.
 

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

 At Tue, 08 Aug 2000 05:10:18 +1000, Bruce Evans wrote:
 
 > 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
 
 What do you think about the following addition to you patched version?
 
 Index: style.9
 ===================================================================
 RCS file: /home/ncvs/src/share/man/man9/style.9,v
 retrieving revision 1.37
 diff -u -r1.37 style.9
 --- style.9	2000/08/08 09:54:57	1.37
 +++ style.9	2000/08/08 11:40:15
 @@ -110,14 +110,16 @@
  and
  .Sq \&}
  .Pc .
 -Right-justify the
 -backslashes; it makes it easier to read.
 +Backslashes should be right-justified for easier reading.
  If the macro encapsulates a compound statement, enclose it in a
  .Dq Li do
  loop,
  so that it can safely be used in 
  .Dq Li if
  statements.
 +Decleration macro should be complete declerations and 
 +.Ql struck __hack  
 +should be used to require a statement-terminating semicolon.
  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.
 @@ -126,6 +128,11 @@
  	variable = (x) + (y);						\e
  	(y) += 2;							\e
  } while(0)
 +.Ed
 +.Bd -literal -offset 0i
 +#define	DECL(x, y)							\e
 +	struct example x = {y};						\e
 +	struct __hack
  .Ed
  .Pp
  Enumeration values are all uppercase.
 
 
 
 > > 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.
 
 
 If the above is accetable I think we should change the SYSINIT definition:
 Index: kernel.h
 ===================================================================
 RCS file: /home/ncvs/src/sys/sys/kernel.h,v
 retrieving revision 1.65
 diff -u -r1.65 kernel.h
 --- kernel.h	2000/05/26 02:06:54	1.65
 +++ kernel.h	2000/08/08 11:45:48
 @@ -220,11 +220,13 @@
  		func,						\
  		ident						\
  	};							\
 -	DATA_SET(sysinit_set,uniquifier ## _sys_init);
 +	DATA_SET(sysinit_set,uniquifier ## _sys_init);		\
 +	struct __hack
  
  #define	SYSINIT(uniquifier, subsystem, order, func, ident)	\
  	C_SYSINIT(uniquifier, subsystem, order,			\
 -	(sysinit_cfunc_t)(sysinit_nfunc_t)func, (void *)ident)
 +	(sysinit_cfunc_t)(sysinit_nfunc_t)func, (void *)ident);	\
 +	struct __hack
  
  /*
   * Called on module unload: no special processing
 
 
 
 
 However this needs to be done carefully :-)
 
 My suggestion is
 1) change all SYSINIT(...) to SYSINIT(...);  approx 100 places
 	even thou this introduces -pedantic synatx error
 2) buildworld / kernel and make sure it still builds
 3) commit
 4) apply the above patch to sys/kernel.h which removes the 
 	-pedantic syntax error
 5) buildworld / kernel and make sure it still builds
 6) commit
 
 
 I can prepare patches for step 1) for -current and run it 
 throu a -current buildworld, but I run 4-Stable. And anyone 
 interested in commiting this should run it on a current for awhile.
 
 
 Does this sound like a good solution for this PR 
 (or is this to much fidling w/ holy stuff)?
 If not, close it and I spend my time with something else :-)
 
 /Johan K
 
 
 
 
State-Changed-From-To: open->closed 
State-Changed-By: remko 
State-Changed-When: Fri Dec 29 20:20:52 UTC 2006 
State-Changed-Why:  
After all this time nobody looked into it, I think we did the best we 
can do for this, close the PR. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=9869 
>Unformatted:
