Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Keith Thompson <kst-u@mib.org> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: #define with semicolon |
| Date | 2011-07-13 12:38 -0700 |
| Organization | None to speak of |
| Message-ID | <lnpqleq8dh.fsf@nuthaus.mib.org> (permalink) |
| References | <ab0d55fe-25e5-482b-811e-c475aa6065c3@c29g2000yqd.googlegroups.com> |
cc <scatnubbs@hotmail.com> writes:
> Is it acceptable practice to have a #define with a semicolon in it,
> such as:
>
> #define SMALL 1;
>
> I didn't think it was, but a very good friend of mine claims it's
> perfectly acceptable if you want to prevent the #define from being
> used in an expression like if(SMALL).
Why would you want to prevent it from being used in an expression?
I think "1;" is a poor example of what your friend is talking about.
I'd be interested in seeing a better example.
A #define can contain any token sequence you like. The macro name
will be expanded to that token sequence every time you use it.
If you want that token sequence to include a semicolon, then you
should have a semicolon in the definition.
But most of the time, a macro expansion is used either in an
expression context (in which case it *shouldn't* have any semicolons,
and it should be protected by parentheses where necessary), or
in a statement context (in which case, if it consists of multiple
substatements, you need to use the "do { ... } while (0)" trick).
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar
#define with semicolon cc <scatnubbs@hotmail.com> - 2011-07-13 11:19 -0700
Re: #define with semicolon Keith Thompson <kst-u@mib.org> - 2011-07-13 12:38 -0700
Re: #define with semicolon cc <scatnubbs@hotmail.com> - 2011-07-13 12:56 -0700
Re: #define with semicolon Dr Nick <3-nospam@temporary-address.org.uk> - 2011-07-13 21:09 +0100
Re: #define with semicolon Keith Thompson <kst-u@mib.org> - 2011-07-13 13:30 -0700
Re: #define with semicolon Hallvard B Furuseth <h.b.furuseth@usit.uio.no> - 2011-07-14 13:03 +0200
Re: #define with semicolon Gene <gene.ressler@gmail.com> - 2011-07-14 05:27 -0700
Re: #define with semicolon Roberto Waltman <usenet@rwaltman.com> - 2011-07-15 10:54 -0400
Re: #define with semicolon Keith Thompson <kst-u@mib.org> - 2011-07-15 09:05 -0700
Re: #define with semicolon Robert Wessel <robertwessel2@yahoo.com> - 2011-07-15 11:49 -0500
Re: #define with semicolon Noob <root@127.0.0.1> - 2011-07-21 15:31 +0200
Re: #define with semicolon "J. J. Farrell" <jjf@bcs.org.uk> - 2011-07-22 01:51 +0100
Re: #define with semicolon Harald van Dijk <truedfx@gmail.com> - 2011-07-13 13:51 -0700
Re: #define with semicolon Keith Thompson <kst-u@mib.org> - 2011-07-13 14:01 -0700
Re: #define with semicolon Harald van Dijk <truedfx@gmail.com> - 2011-07-13 14:14 -0700
Re: #define with semicolon Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2011-07-13 17:10 -0600
Re: #define with semicolon Keith Thompson <kst-u@mib.org> - 2011-07-13 16:20 -0700
Re: #define with semicolon Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2011-07-14 14:03 +0300
Re: #define with semicolon Ben Bacarisse <ben.usenet@bsb.me.uk> - 2011-07-14 01:22 +0100
Re: #define with semicolon Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2011-07-22 15:50 +0300
Re: #define with semicolon Todd Carnes <toddcarnes@gmail.com> - 2011-07-22 21:46 +0000
Re: #define with semicolon Ian Collins <ian-news@hotmail.com> - 2011-07-23 09:54 +1200
Re: #define with semicolon Todd Carnes <toddcarnes@gmail.com> - 2011-07-22 22:21 +0000
Re: #define with semicolon Seebs <usenet-nospam@seebs.net> - 2011-07-23 00:12 +0000
Re: #define with semicolon Todd Carnes <toddcarnes@gmail.com> - 2011-07-23 00:37 +0000
Re: #define with semicolon Willem <willem@toad.stack.nl> - 2011-07-23 09:55 +0000
Re: #define with semicolon Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2011-07-22 15:54 -0600
Re: #define with semicolon Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2011-07-23 01:14 +0300
Re: #define with semicolon Todd Carnes <toddcarnes@gmail.com> - 2011-07-22 22:28 +0000
Re: #define with semicolon Phil Carmody <thefatphil_demunged@yahoo.co.uk> - 2011-07-23 02:52 +0300
Re: #define with semicolon Todd Carnes <toddcarnes@gmail.com> - 2011-07-23 00:14 +0000
Re: #define with semicolon Keith Thompson <kst-u@mib.org> - 2011-07-22 16:52 -0700
Re: #define with semicolon Todd Carnes <toddcarnes@gmail.com> - 2011-07-23 00:07 +0000
Re: #define with semicolon Ben Pfaff <blp@cs.stanford.edu> - 2011-07-13 13:04 -0700
Re: #define with semicolon Barry Schwarz <schwarzb@dqel.com> - 2011-07-13 17:11 -0700
Re: #define with semicolon Walter Banks <walter@bytecraft.com> - 2011-07-14 08:11 -0400
Re: #define with semicolon pete <pfiland@mindspring.com> - 2011-07-14 08:24 -0400
Re: #define with semicolon "io_x" <a@b.c.invalid> - 2011-07-14 17:34 +0200
Re: #define with semicolon cc <scatnubbs@hotmail.com> - 2011-07-15 04:12 -0700
Re: #define with semicolon Anders Wegge Keller <wegge@wegge.dk> - 2011-07-15 14:49 +0200
Re: #define with semicolon Snit <usenet@gallopinginsanity.com> - 2011-07-15 08:37 -0700
Re: #define with semicolon "cc" <scatnubs@hotmail.com> - 2011-07-19 11:03 -0700
Re: #define with semicolon Keith Thompson <kst-u@mib.org> - 2011-07-15 09:23 -0700
Re: #define with semicolon cc <scatnubbs@hotmail.com> - 2011-07-15 10:37 -0700
Re: #define with semicolon Snit <usenet@gallopinginsanity.com> - 2011-07-15 13:07 -0700
Re: #define with semicolon Keith Thompson <kst-u@mib.org> - 2011-07-15 13:26 -0700
Re: #define with semicolon Snit <usenet@gallopinginsanity.com> - 2011-07-15 13:31 -0700
Re: #define with semicolon cc <scatnubbs@hotmail.com> - 2011-07-19 08:55 -0700
Re: #define with semicolon "Kleuskes & Moos" <kleuske@xs4all.nl> - 2011-07-19 14:12 -0700
Re: #define with semicolon "cc" <scatnubs@hotmail.com> - 2011-07-19 11:05 -0700
Re: #define with semicolon cc <scatnubbs@hotmail.com> - 2011-07-19 11:18 -0700
Re: #define with semicolon Snit <usenet@gallopinginsanity.com> - 2011-07-19 11:23 -0700
Re: #define with semicolon cc <scatnubbs@hotmail.com> - 2011-07-19 11:31 -0700
Re: #define with semicolon "cc" <scatnubs@hotmail.com> - 2011-07-19 11:05 -0700
Re: #define with semicolon Snit <usenet@gallopinginsanity.com> - 2011-07-15 10:51 -0700
Re: #define with semicolon "cc" <scatnubs@hotmail.com> - 2011-07-19 11:04 -0700
Re: #define with semicolon "J. J. Farrell" <jjf@bcs.org.uk> - 2011-07-20 00:53 +0100
Re: #define with semicolon Snit <usenet@gallopinginsanity.com> - 2011-07-19 16:57 -0700
Re: #define with semicolon gordonb.ethca@burditt.org (Gordon Burditt) - 2011-07-15 10:33 -0500
Re: #define with semicolon Michael Angelo Ravera <maravera@prodigy.net> - 2011-07-22 10:55 -0700
csiph-web