Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!swrinde!ucsd!pacbell.com!decwrl!bacchus.pa.dec.com!shlump.nac.dec.com!tkou02.enet.dec.com!diamond From: diamond@tkou02.enet.dec.com (diamond@tkovoa) Newsgroups: comp.lang.c Subject: Re: Using Macros Message-ID: <1908@tkou02.enet.dec.com> Date: 9 Aug 90 04:57:23 GMT References: <14363@shlump.nac.dec.com> Reply-To: diamond@tkou02.enet.dec.com (diamond@tkovoa) Organization: Digital Equipment Corporation Japan , Tokyo Lines: 40 In article <14363@shlump.nac.dec.com> farrell@onedge.enet.dec.com (Bernard Farrell) writes: >In article <10836@crdgw1.crd.ge.com>, volpe@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@tkou02.enet.dec.com This is me speaking. If you want to hear the company speak, you need DECtalk.