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


Groups > comp.lang.c > #67099

Re: Untyped Variables

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: Untyped Variables
Date 2015-08-10 17:42 -0700
Organization None to speak of
Message-ID <ln1tfaejur.fsf@kst-u.example.com> (permalink)
References (2 earlier) <8eb33dc8-5c47-4b7b-a20e-584166a50d58@googlegroups.com> <55C69FFA.7050309@verizon.net> <mqaadk$2hpv$1@macpro.inf.ed.ac.uk> <lnegjbduvo.fsf@kst-u.example.com> <c2766b55-62de-458d-9a34-7114067bbc11@googlegroups.com>

Show all headers | View raw


David Kleinecke <dkleinecke@gmail.com> writes:
> On Monday, August 10, 2015 at 8:23:37 AM UTC-7, Keith Thompson wrote:
>> richard@cogsci.ed.ac.uk (Richard Tobin) writes:
>> > 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.
>> 
>> Interesting, so it does.
>> 
>> For those who don't have a copy of C90, 6.5.2 covers type
>> specifiers.  A type specifier is one of void, char, short,
>> int, etc.  A declaration starts with a sequence of one or more
>> declaration specifiers, each of which is a storage-class specifier,
>> a type-specifier, or a type-qualifier.  The constraint in 6.5.2
>> restricts the list of type specifiers to one of a list of sets
>> (changed to "multisets" in C99 with the addition of long long,
>> though the wording wasn't updated until C11); for example, you
>> can't have "int int" or "short long" in a declaration.
>> 
>> One of the permitted sets of type specifiers is:
>> 
>>     -- int, signed, signed int, or no type specifiers
>> 
>> So this:
>> 
>>     x;
>> 
>> does not satisfy the grammar, but it is permitted by the constraint.
>> ("auto x;" or "static x;" is permitted by the grammar.)
>> 
>> (Note that "x;" is ambiguous at block scope, where it could be an
>> expression statement; it's unambiguous at file scope where statements
>> are not permitted.  I think C90 has wording to resolve the ambiguity,
>> but I don't know exactly where it does so.)
>> 
>> This is yet another reason to be glad that the implicit int rule
>> is no longer with us.
>  
> I disagree with that reading of the constraint

Now that I look at it again, I think you're right, and I was wrong.

C90's grammar permits a declaration with no type specifiers, such as
"auto x;".  The constraint in 6.5.2 doesn't permit type specifiers to be
omitted where the grammar requires them.  It specifies the *meaning* of
a declaration with no type specifiers (namely that it's equivalent to a
declaration with "int" (or "signed", or "signed int", or "int signed").

    Constraints:
        Each list of type specifiers shall be one of the following sets
        (delimited by commas. when there is more than one set on a
        line); the type specifiers may occur in any order. possibly
        intermixed with the other declaration specifiers.
        ...
        -- int, signed, signed int, or no type specifiers
    ...
    Semantics:
        ...
        Each of the above comma-separated sets designates the same type,
        except that for bit-fields, the type signed int (or signed) may
        differ from int (or no type specifiers).

I'm fairly sure that early C compiler did permit

    x;

at file scope to mean the same thing as

    int x;

gcc treats it that way (with just a warning by default), presumably for
backward compatibility.

>                                                but lets all just ignore
> the problem and never omit a type-specifier.

Indeed.

C99 omits the "or no type specifiers" wording, and adds a constraint:

    At least one type specifier shall be given in the declaration
    specifiers in each declaration, and in the specifier-qualifier list
    in each struct declaration and type name.

> If C were perfect (IMO) "double" would be "float" and "float" would be
> "short float" and "double" would not be a keyword.

And "long double" would be "long float"?

There's a long convention of referring to 32-bit and 64-bit
floating-point as single-precision and double-precision, respectively.

There are a lot of things I'd change if I wanted to make C more nearly
"perfect".  The names of the floating-point types aren't very high on
that list.  (Don't ask; the "list" is purely hypothetical.)

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

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