Using Macros

diamond@tkovoa diamond at tkou02.enet.dec.com
Thu Aug 9 14:57:23 AEST 1990


In article <14363 at shlump.nac.dec.com> farrell at onedge.enet.dec.com (Bernard Farrell) writes:
>In article <10836 at crdgw1.crd.ge.com>, volpe at underdog.crd.ge.com (Christopher R Volpe) writes...
[  if (blah) { stmt1; stmt2; };  ]
>>Can someone with a copy of the Standard tell us if a semicolon is 
>>allowed?
>The Standard simply comments on the Null statement in 3.6.3 as one that
>"performs no operations".   There is no reference to Null statements in
>the context of Block statements, 3.6.2., nor would I expect there
>to be because the fact that the statement has a curly brace in front of
>it really shouldn't modify it's meaning.

That semicolon is allowed.  There is an "if" statement followed by a null
statement.  The problem is that the USER might have intended that to be
only half of an "if" statement.  The user might have an "else" following:
  if (blah) MACRO; else JUNK;
The user does not expect an error message for the "else".

Coders of macros should make it easier for users -- just like libraries,
programming languages, editors, and other tools that will be used by
many more people than the developers.  So the following is common:
  #define MACRO  do { some_statement; more_statements; } while 0
Of course, if the statements can be written as expressions, then it
is preferable to make the macro into a comma (or similar) expression.

>I believe K&R (n) was probably placating Pascal converts, and meant
>no semicolon necessary.

Huh?  In
  if (blah) { stmt1; stmt2; } /* try a ; here? */ else stmt3;
a semicolon CANNOT be put there.

Both Pascal and C have null statements.
Both Pascal and C programmers criticize each other's language for style
of semicolon usage, both make errors and write false criticisms, and
both overlook shortcomings in their own languages.  In order to placate
correct criticisms, both languages could use some adjustments (which in
some cases were proposed and rejected).
-- 
Norman Diamond, Nihon DEC     diamond at tkou02.enet.dec.com
This is me speaking.  If you want to hear the company speak, you need DECtalk.



More information about the Comp.lang.c mailing list