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


Groups > comp.lang.c > #67106

Re: Untyped Variables

From Ben Bacarisse <ben.usenet@bsb.me.uk>
Newsgroups comp.lang.c
Subject Re: Untyped Variables
Date 2015-08-11 11:21 +0100
Organization A noiseless patient Spider
Message-ID <87bneeazx3.fsf@bsb.me.uk> (permalink)
References (3 earlier) <55C69FFA.7050309@verizon.net> <mqaadk$2hpv$1@macpro.inf.ed.ac.uk> <fa3e2bb7-f1ac-468c-83bb-282deec9b26d@googlegroups.com> <87h9o6bquz.fsf@bsb.me.uk> <lnwpx2d1jm.fsf@kst-u.example.com>

Show all headers | View raw


Keith Thompson <kst-u@mib.org> writes:

> Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
>> David Kleinecke <dkleinecke@gmail.com> writes:
>>> On Monday, August 10, 2015 at 6:55:11 AM UTC-7, Richard Tobin wrote:
>>>> In article <55C69FFA.7050309@verizon.net>,
>>>> James Kuyper  <jameskuyper@verizon.net> wrote:
>>>> 
>>>> >On 08/08/2015 07:06 PM, David Kleinecke wrote:
>>>> >...
>>>> >> I haven't been thinking of constraints as part of syntax. ...
>>>> 
>>>> >It would be more accurate to say that some constraints constrain the
>>>> >syntax.
>>>> 
>>>> It would make sense that a program must conform to both the grammar
>>>> and the constraints.
>>>> 
>>>> But in the case of implicit int in C90, the "constraint" in 6.5.2
>>>> explicitly allows something that is not allowed by the grammar.
>>>  
>>> If you are saying that the constraint explicitly legalizes
>>>     a;
>>> you are IMO wrong. It legalizes having no type specifier but the
>>> storage-class-specifiers and type-qualifiers remain to fulfill the
>>> grammar's requirement for a declaration-specifier.
>>
>> I can't see how you arrive at that conclusion.  The grammar permits
>> declarations with nothing but type specifiers, and the constraint (which
>> is really a permission in the this case) permits these to consist of no
>> type specifiers.  Where do you find support for your view that there
>> must be a storage class or type qualifier when here is no type
>> specifier?
>
> The syntax for a declaration, in C90 6.5, indicates that a declaration
> must begin with a storage-class-specifier, a type-specifier, or a
> type-qualifier.  This makes
>     a;
> a syntax error (at file scope, where statements are not permitted).
>
> The constraint in C90 6.5.2 says that "Each list of type specifiers
> shall be one of the following sets ...", where "no type specifiers" is
> one possibility, grouped with int, signed, and signed int.
>
> The constraint forbids things like "void float" (or "long long", which
> was not permitted prior to C99).
>
> 6.5.2 specifies the *meaning* of a declaration with no type specifiers,
> such as
>     auto x;
>     volatile y;
>     z();
>
> It does not change the context in which such a declaration is
> permitted.  In particular, it does not override the grammar to
> permit a declaration that doesn't have a storage class specifier,
> a type specifier, *or* a type qualifier.  An empty sequence of type
> specifiers is permitted only in a declaration that has a storage
> class specifier and/or a type qualifier.

Yes, I'm sure (now!) that this is the right interpretation.  Oddly it
was clarified for me by reading K&R1 when I went to check what used to
be the case.  The wording there is much simpler; after giving the syntax
they say "if the type-specifier is missing from a declaration it is
taken to be int".  This seems less ambiguous than wording that could be
taken to imply that an empty list is a valid set of type specifiers.

<snip>
> (B did permit such declarations at file scope.)

Right, and, coming from B to old C as I did, that is no doubt part of
the reason why I used to think that "implicit int" was more general than
it ever actually was.  But there's another reason.  Much more common was
this old syntax (still permitted in C90):

  f()
  {
      ...
  }

It's possible to assume (and I certainly did) that this syntax is valid
because the type-specifiers can be empty.  In fact, its valid because
the declaration-specifiers are specifically optional in a function
declaration.  It means you can't (as I unthinkingly thought you could in
the old days) simply remove the function body and append a semi-colon to
turn a function definition into a declaration.  In this case you need to
add extern or int or whatever.

-- 
Ben.

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Untyped Variables David Kleinecke <dkleinecke@gmail.com> - 2015-08-07 18:19 -0700
  Re: Untyped Variables Lőrinczy Zsigmond <nospam@for.me> - 2015-08-08 06:53 +0200
  Re: Untyped Variables James Kuyper <jameskuyper@verizon.net> - 2015-08-08 11:09 -0400
    Re: Untyped Variables Keith Thompson <kst-u@mib.org> - 2015-08-08 12:09 -0700
      Re: Untyped Variables James Kuyper <jameskuyper@verizon.net> - 2015-08-08 14:24 -0400
    Re: Untyped Variables Keith Thompson <kst-u@mib.org> - 2015-08-08 12:54 -0700
      Re: Untyped Variables David Kleinecke <dkleinecke@gmail.com> - 2015-08-08 16:06 -0700
        Re: Untyped Variables Keith Thompson <kst-u@mib.org> - 2015-08-08 17:29 -0700
          Re: Untyped Variables David Kleinecke <dkleinecke@gmail.com> - 2015-08-09 17:52 -0700
            Re: Untyped Variables Ian Collins <ian-news@hotmail.com> - 2015-08-10 12:57 +1200
            Re: Untyped Variables Keith Thompson <kst-u@mib.org> - 2015-08-10 08:41 -0700
              Re: Untyped Variables David Kleinecke <dkleinecke@gmail.com> - 2015-08-10 17:06 -0700
        Re: Untyped Variables Richard Damon <Richard@Damon-Family.org> - 2015-08-08 19:44 -0400
        Re: Untyped Variables James Kuyper <jameskuyper@verizon.net> - 2015-08-08 20:34 -0400
          Re: Untyped Variables glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-08-09 02:03 +0000
            Re: Untyped Variables Richard Damon <Richard@Damon-Family.org> - 2015-08-08 22:52 -0400
              Re: Untyped Variables glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-08-09 04:57 +0000
                Re: Untyped Variables Joe Pfeiffer <pfeiffer@cs.nmsu.edu> - 2015-08-09 09:58 -0600
                Re: Untyped Variables Malcolm McLean <malcolm.mclean5@btinternet.com> - 2015-08-10 03:54 -0700
                Re: Untyped Variables Richard Damon <Richard@Damon-Family.org> - 2015-08-09 16:59 -0400
          Re: Untyped Variables David Kleinecke <dkleinecke@gmail.com> - 2015-08-09 18:02 -0700
            Re: Untyped Variables James Kuyper <jameskuyper@verizon.net> - 2015-08-10 11:01 -0400
              Re: Untyped Variables James Kuyper <jameskuyper@verizon.net> - 2015-08-10 13:20 -0400
              Re: Untyped Variables David Kleinecke <dkleinecke@gmail.com> - 2015-08-10 16:54 -0700
                Re: Untyped Variables James Kuyper <jameskuyper@verizon.net> - 2015-08-11 00:20 -0400
            Re: Untyped Variables Keith Thompson <kst-u@mib.org> - 2015-08-10 08:11 -0700
              Re: Untyped Variables David Kleinecke <dkleinecke@gmail.com> - 2015-08-10 17:15 -0700
                Re: Untyped Variables James Kuyper <jameskuyper@verizon.net> - 2015-08-11 00:30 -0400
                Re: Untyped Variables David Kleinecke <dkleinecke@gmail.com> - 2015-08-11 16:50 -0700
                Re: Untyped Variables Keith Thompson <kst-u@mib.org> - 2015-08-11 17:24 -0700
                Re: Untyped Variables Richard Heathfield <rjh@cpax.org.uk> - 2015-08-12 01:37 +0100
                Re: Untyped Variables glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-08-12 04:46 +0000
                Re: Untyped Variables David Kleinecke <dkleinecke@gmail.com> - 2015-08-12 18:12 -0700
                Re: Untyped Variables Keith Thompson <kst-u@mib.org> - 2015-08-13 12:08 -0700
                Re: Untyped Variables David Kleinecke <dkleinecke@gmail.com> - 2015-08-13 16:25 -0700
                Re: Untyped Variables Keith Thompson <kst-u@mib.org> - 2015-08-14 10:36 -0700
                Re: Untyped Variables Bartc <bc@freeuk.com> - 2015-08-14 19:13 +0100
                Re: Untyped Variables Keith Thompson <kst-u@mib.org> - 2015-08-11 07:58 -0700
          Re: Untyped Variables richard@cogsci.ed.ac.uk (Richard Tobin) - 2015-08-10 13:53 +0000
            Re: Untyped Variables Keith Thompson <kst-u@mib.org> - 2015-08-10 08:29 -0700
              Re: Untyped Variables David Kleinecke <dkleinecke@gmail.com> - 2015-08-10 17:01 -0700
                Re: Untyped Variables Keith Thompson <kst-u@mib.org> - 2015-08-10 17:42 -0700
                Re: Untyped Variables glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-08-11 02:56 +0000
            Re: Untyped Variables David Kleinecke <dkleinecke@gmail.com> - 2015-08-10 16:50 -0700
              Re: Untyped Variables Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-08-11 01:39 +0100
                Re: Untyped Variables Keith Thompson <kst-u@mib.org> - 2015-08-10 19:03 -0700
                Re: Untyped Variables Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-08-11 11:21 +0100
                Re: Untyped Variables David Kleinecke <dkleinecke@gmail.com> - 2015-08-11 16:37 -0700

csiph-web