Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #67560

Re: Labels

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: Labels
Date 2015-08-16 21:24 -0700
Organization None to speak of
Message-ID <lnlhda7dau.fsf@kst-u.example.com> (permalink)
References (2 earlier) <874mk0goix.fsf@bsb.me.uk> <mqokd9$qv5$1@dont-email.me> <ln4mk09e0k.fsf@kst-u.example.com> <mqplbf$ipu$1@dont-email.me> <c7547393-536e-4169-87e9-bf4fa5fc4c49@googlegroups.com>

Show all headers | View raw


David Kleinecke <dkleinecke@gmail.com> writes:
> On Sunday, August 16, 2015 at 2:34:31 AM UTC-7, Bart wrote:
>> On 16/08/2015 03:13, Keith Thompson wrote:
>> > Bartc <bc@freeuk.com> writes:
>> > [...]
>> >> But even knowing a starter symbol is a typedef name, then with 'T(' you
>> >> might still be a long way from knowing if this is a simple variable
>> >> declaration, or the start of a 1000-line function definition.
>> >
>> > At block scope, function definitions are not permitted.  At file scope,
>> > a function definition cannot start with 'T('; it requires at least a
>> > type name and an identifier.
>> 
>> The following seems to be legal:
>> 
>> #include <stdio.h>
>> 
>> typedef int T;
>> 
>> T(main)(void) {
>>     printf("Hello World\n");
>> }
>
> It is my understanding that typedefs are not actual types but rather 
> a kind of alsias for the type they are defined as. Hence
>    typedef int T;
> makes
>    T main ....
> compile eactly as if you had written
>    int main ...
>
> The compiler must maintain internally a table of what typedef names
> mean. The meaning part of that table is a (possibly very complicated)
> expression in non-typedef types and their decoration.  

Bart's point was that the parentheses around main are permitted
(something I initially didn't notice either).

I had incorrectly said that 'T(' cannot start a function definition.
Bart came up with a counterexample, using a typedef and extra
parentheses.

Yes, a typedef creates a new name for an existing type, not a
new type.  That's not the point here.  This:

    int(main)(void) { /* ... */ }

which is more commonly written as

    int main(void) { /* ... */ }

would have made the same point, except that my incorrect statement
involved an identifier T rather than the keyword int.

-- 
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


Thread

Labels David Kleinecke <dkleinecke@gmail.com> - 2015-08-15 09:46 -0700
  Re: Labels James Kuyper <jameskuyper@verizon.net> - 2015-08-15 14:49 -0400
    Re: Labels David Kleinecke <dkleinecke@gmail.com> - 2015-08-15 18:48 -0700
  Re: Labels Bartc <bc@freeuk.com> - 2015-08-15 18:27 +0100
    Re: Labels Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-08-15 23:44 +0100
      Re: Labels James Kuyper <jameskuyper@verizon.net> - 2015-08-15 19:04 -0400
        Re: Labels Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-08-16 00:47 +0100
          Re: Labels James Kuyper <jameskuyper@verizon.net> - 2015-08-15 20:20 -0400
            Re: Labels Bartc <bc@freeuk.com> - 2015-08-16 01:56 +0100
              Re: Labels Keith Thompson <kst-u@mib.org> - 2015-08-15 19:47 -0700
                Re: Labels James Kuyper <jameskuyper@verizon.net> - 2015-08-16 11:59 -0400
            Re: Labels Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-08-16 22:42 +0100
              Re: Labels James Kuyper <jameskuyper@verizon.net> - 2015-08-16 20:39 -0400
                Re: Labels Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-08-17 03:16 +0100
        Re: Labels David Kleinecke <dkleinecke@gmail.com> - 2015-08-15 19:01 -0700
      Re: Labels Bartc <bc@freeuk.com> - 2015-08-16 01:11 +0100
        Re: Labels Keith Thompson <kst-u@mib.org> - 2015-08-15 19:13 -0700
          Re: Labels Bartc <bc@freeuk.com> - 2015-08-16 10:34 +0100
            Re: Labels Keith Thompson <kst-u@mib.org> - 2015-08-16 13:58 -0700
            Re: Labels David Kleinecke <dkleinecke@gmail.com> - 2015-08-16 20:42 -0700
              Re: Labels Keith Thompson <kst-u@mib.org> - 2015-08-16 21:24 -0700
                Re: Labels David Kleinecke <dkleinecke@gmail.com> - 2015-08-17 18:01 -0700
              Re: Labels Bartc <bc@freeuk.com> - 2015-08-17 11:04 +0100
        Re: Labels David Kleinecke <dkleinecke@gmail.com> - 2015-08-15 19:04 -0700
        Re: Labels Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-08-16 23:55 +0100
    Re: Labels David Kleinecke <dkleinecke@gmail.com> - 2015-08-15 19:00 -0700

csiph-web