Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Keith Thompson <kst-u@mib.org> |
| Newsgroups | comp.lang.c |
| Subject | Re: Making C more beautiful by not using macros with arguments |
| Date | Sun, 31 May 2015 13:04:35 -0700 |
| Organization | None to speak of |
| Lines | 65 |
| Message-ID | <87r3pwikdo.fsf@kst-u.example.com> (permalink) |
| References | <032b4cc1-a813-4caa-a810-569e1ea3b0ab@googlegroups.com> <87h9qvkzpb.fsf@bsb.me.uk> <0f75266c-9fff-439e-98a3-4140f21e04d5@googlegroups.com> <87fv6dkd7f.fsf@bsb.me.uk> <mkdf7r$s25$1@dont-email.me> <87a8wlk5o3.fsf@bsb.me.uk> <mkejo1$k6c$1@dont-email.me> <87zj4lhxsc.fsf@bsb.me.uk> <ce45f467-6f93-415e-b23f-abd26728bf7e@googlegroups.com> <mkffqo$luc$1@dont-email.me> |
| Mime-Version | 1.0 |
| Content-Type | text/plain |
| Injection-Info | mx02.eternal-september.org; posting-host="9be37d943435275679235b07c7947eef"; logging-data="31299"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19HOcqLdDXrPxTM+G2eoJR2" |
| User-Agent | Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) |
| Cancel-Lock | sha1:2yX9IXdpztUdSGYf3pNGqP6wRRQ= sha1:kuw+eGIf09v61ViL34LuYaILxwQ= |
| Xref | csiph.com comp.lang.c:62882 |
Show key headers only | View raw
Bartc <bc@freeuk.com> writes:
[...]
> As an example of the quirks, take this simple program:
>
> int main(void) {}
>
> How many people know that it can also be written like this:
>
> int (main(void)) {}
>
> (with the extra parentheses)? At least one C compiler doesn't!
I didn't know that, but I verified it by compiling with gcc and checking
the syntax in the standard.
Which compiler?
Incidentally, cdecl recognizes int (main(void)) -- and any compiler that
doesn't is non-conforming.
> While the prototype for a function 'g', taking parameter type 'h', and
> returning type 'f', can be written as:
>
> f(g(h));
>
> Which happens to look exactly like a couple of nested function calls!
> (This means it's not possible to write a simple syntax translator for
> C.)
The difference is that f and h are type names, which are syntactically
distinct from identifiers.
This:
int(g(int));
is valid, but is more clearly written as
int g(int);
Parentheses are permitted in declarators for the same reason they're
allowed in expressions: to specify grouping and improve clarity. C's
declaration syntax is peculiar enough that the result can be confusing.
In this case, int is a keyword, not an identifier, so there's no real
ambiguity. If you use a typedef name:
typedef int foo;
foo(g(foo));
// or foo g(foo);
it *seems* more ambiguous, but it isn't really. Typedefs were added to
the language relatively late (I don't remember whether K&R1 had them),
and they caused some syntactic problems. A typedef declaration
effectively creates a new keyword, but only within the scope of the
declaration -- except that the identifier can be redeclared in an inner
scope. This makes it impossible to parse C without feedback from the
symbol table.
--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"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 | Unroll thread
Making C more beautiful by not using macros with arguments David Kleinecke <dkleinecke@gmail.com> - 2015-05-29 10:36 -0700
Re: Making C more beautiful by not using macros with arguments Bartc <bc@freeuk.com> - 2015-05-29 19:04 +0100
Re: Making C more beautiful by not using macros with arguments David Kleinecke <dkleinecke@gmail.com> - 2015-05-30 07:30 -0700
Re: Making C more beautiful by not using macros with arguments Bartc <bc@freeuk.com> - 2015-05-30 15:51 +0100
Re: Making C more beautiful by not using macros with arguments Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-29 19:26 +0100
Re: Making C more beautiful by not using macros with arguments David Kleinecke <dkleinecke@gmail.com> - 2015-05-30 07:38 -0700
Re: Making C more beautiful by not using macros with arguments Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-30 21:44 +0100
Re: Making C more beautiful by not using macros with arguments Bartc <bc@freeuk.com> - 2015-05-30 23:58 +0100
Re: Making C more beautiful by not using macros with arguments Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-31 00:27 +0100
Re: Making C more beautiful by not using macros with arguments Bartc <bc@freeuk.com> - 2015-05-31 10:21 +0100
Re: Making C more beautiful by not using macros with arguments Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-31 11:00 +0100
Re: Making C more beautiful by not using macros with arguments David Kleinecke <dkleinecke@gmail.com> - 2015-05-31 09:45 -0700
Re: Making C more beautiful by not using macros with arguments Bartc <bc@freeuk.com> - 2015-05-31 18:20 +0100
Re: Making C more beautiful by not using macros with arguments Keith Thompson <kst-u@mib.org> - 2015-05-31 13:04 -0700
Re: Making C more beautiful by not using macros with arguments Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-05-31 16:11 -0400
Re: Making C more beautiful by not using macros with arguments Bartc <bc@freeuk.com> - 2015-05-31 21:48 +0100
Re: Making C more beautiful by not using macros with arguments Keith Thompson <kst-u@mib.org> - 2015-05-31 14:22 -0700
Re: Making C more beautiful by not using macros with arguments David Kleinecke <dkleinecke@gmail.com> - 2015-06-01 11:33 -0700
Re: Making C more beautiful by not using macros with arguments Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-31 20:37 +0100
Re: Making C more beautiful by not using macros with arguments Keith Thompson <kst-u@mib.org> - 2015-05-31 14:18 -0700
Re: Making C more beautiful by not using macros with arguments Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-31 22:44 +0100
Re: Making C more beautiful by not using macros with arguments Bartc <bc@freeuk.com> - 2015-05-31 23:16 +0100
Re: Making C more beautiful by not using macros with arguments David Kleinecke <dkleinecke@gmail.com> - 2015-06-01 11:58 -0700
Re: Making C more beautiful by not using macros with arguments Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-06-02 01:14 +0100
Re: Making C more beautiful by not using macros with arguments Bartc <bc@freeuk.com> - 2015-06-02 10:31 +0100
Re: Making C more beautiful by not using macros with arguments Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-06-02 11:06 +0100
Re: Making C more beautiful by not using macros with arguments Bartc <bc@freeuk.com> - 2015-06-02 11:39 +0100
Re: Making C more beautiful by not using macros with arguments "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-06-02 04:02 -0700
Re: Making C more beautiful by not using macros with arguments Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-06-02 12:24 +0100
Re: Making C more beautiful by not using macros with arguments Noob <root@127.0.0.1> - 2015-06-02 15:41 +0200
Re: Making C more beautiful by not using macros with arguments Richard Heathfield <rjh@cpax.org.uk> - 2015-06-02 15:00 +0100
Re: Trolls/Cranks/Kooks Noob <root@127.0.0.1> - 2015-06-02 16:41 +0200
Re: Trolls/Cranks/Kooks Richard Heathfield <rjh@cpax.org.uk> - 2015-06-02 15:56 +0100
Re: Trolls/Cranks/Kooks Noob <root@127.0.0.1> - 2015-06-02 17:09 +0200
Re: Trolls/Cranks/Kooks Richard Heathfield <rjh@cpax.org.uk> - 2015-06-02 16:17 +0100
Re: Making C more beautiful by not using macros with arguments Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-06-02 15:58 +0100
Re: Making C more beautiful by not using macros with arguments Dr Nick <nospam-4@temporary-address.org.uk> - 2015-06-02 19:32 +0100
Re: Making C more beautiful by not using macros with arguments David Kleinecke <dkleinecke@gmail.com> - 2015-06-02 11:00 -0700
Re: Making C more beautiful by not using macros with arguments Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-06-02 20:13 +0100
Re: Making C more beautiful by not using macros with arguments Keith Thompson <kst-u@mib.org> - 2015-05-30 15:17 -0700
Re: Making C more beautiful by not using macros with arguments David Kleinecke <dkleinecke@gmail.com> - 2015-05-31 09:12 -0700
Re: Making C more beautiful by not using macros with arguments Keith Thompson <kst-u@mib.org> - 2015-05-31 13:29 -0700
Re: Making C more beautiful by not using macros with arguments David Brown <david.brown@hesbynett.no> - 2015-05-31 17:28 +0200
Re: Making C more beautiful by not using macros with arguments Morris Dovey <mrdovey@iedu.com> - 2015-05-29 13:35 -0500
Re: Making C more beautiful by not using macros with arguments "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-05-29 13:19 -0700
Re: Making C more beautiful by not using macros with arguments "Chris M. Thomasson" <nospam@nospam.nospam> - 2015-05-29 13:25 -0700
Re: Making C more beautiful by not using macros with arguments Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2015-05-29 14:23 -0600
Re: Making C more beautiful by not using macros with arguments Keith Thompson <kst-u@mib.org> - 2015-05-29 14:16 -0700
Re: Making C more beautiful by not using macros with arguments David Kleinecke <dkleinecke@gmail.com> - 2015-05-30 07:46 -0700
Re: Making C more beautiful by not using macros with arguments Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2015-05-30 18:28 -0400
Re: Making C more beautiful by not using macros with arguments David Kleinecke <dkleinecke@gmail.com> - 2015-05-31 09:27 -0700
Re: Making C more beautiful by not using macros with arguments Bartc <bc@freeuk.com> - 2015-05-31 17:59 +0100
Re: Making C more beautiful by not using macros with arguments David Kleinecke <dkleinecke@gmail.com> - 2015-06-01 11:24 -0700
Re: Making C more beautiful by not using macros with arguments Keith Thompson <kst-u@mib.org> - 2015-06-01 12:15 -0700
Re: Making C more beautiful by not using macros with arguments David Kleinecke <dkleinecke@gmail.com> - 2015-06-01 12:21 -0700
Re: Making C more beautiful by not using macros with arguments Keith Thompson <kst-u@mib.org> - 2015-06-01 12:53 -0700
Re: Making C more beautiful by not using macros with arguments Keith Thompson <kst-u@mib.org> - 2015-05-31 13:36 -0700
Re: Making C more beautiful by not using macros with arguments David Brown <david.brown@hesbynett.no> - 2015-05-31 23:26 +0200
Re: Making C more beautiful by not using macros with arguments Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-05-31 23:09 +0100
Re: Making C more beautiful by not using macros with arguments luser droog <luser.droog@gmail.com> - 2015-05-31 15:51 -0700
Re: Making C more beautiful by not using macros with arguments David Kleinecke <dkleinecke@gmail.com> - 2015-06-01 12:08 -0700
Re: Making C more beautiful by not using macros with arguments James Kuyper <jameskuyper@verizon.net> - 2015-06-01 12:38 -0400
Re: Making C more beautiful by not using macros with arguments Dr Nick <nospam-4@temporary-address.org.uk> - 2015-06-01 19:20 +0100
Re: Making C more beautiful by not using macros with arguments David Kleinecke <dkleinecke@gmail.com> - 2015-06-01 12:18 -0700
Re: Making C more beautiful by not using macros with arguments Keith Thompson <kst-u@mib.org> - 2015-05-30 15:43 -0700
Re: Making C more beautiful by not using macros with arguments David Kleinecke <dkleinecke@gmail.com> - 2015-05-31 09:32 -0700
Re: Making C more beautiful by not using macros with arguments Les Cargill <lcargill99@comcast.com> - 2015-05-29 22:07 -0500
Making C more beautiful by not using macros with arguments rick.c.hodgin@gmail.com - 2015-05-30 09:22 -0700
Re: Making C more beautiful by not using macros with arguments Morris Dovey <mrdovey@iedu.com> - 2015-05-30 14:22 -0500
Re: Making C more beautiful by not using macros with arguments Bartc <bc@freeuk.com> - 2015-05-30 21:29 +0100
Re: Making C more beautiful by not using macros with arguments Morris Dovey <mrdovey@iedu.com> - 2015-05-30 22:15 -0500
Re: Making C more beautiful by not using macros with arguments Morris Dovey <mrdovey@iedu.com> - 2015-06-08 20:16 -0500
Re: Making C more beautiful by not using macros with arguments David Brown <david.brown@hesbynett.no> - 2015-05-31 17:32 +0200
Re: Making C more beautiful by not using macros with arguments Richard Heathfield <rjh@cpax.org.uk> - 2015-06-01 22:51 +0100
csiph-web