🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #6175

Re: Is `char const *foo;' legal?

#6175
From: Steve Emmerson
Date: Thu, 11 Jan 1990 15:29
45 lines
1991 bytes
Ron Guilmette, <rfg@paris.ics.uci.edu>, writes with regard to the following 
declaration:

>	char const *foo;

>So let me just ask the general question: "Are such declarations both
>syntactically and semantically legal?"

I cannot speak on the standard since I don't have one.  K&R-II, however
indicates that the above is syntactically and semantically valid.  The
above string can be generated by the following sequence (cf. appendix A13):

	declaration

	declaration-specifiers init-declarator-list(opt) ";"

	storate-class-specifier declaration-specifiers(opt) init-declarator ";"

	"char" type-qualifier declaration-specifiers(opt) declarator ";"

	"char" "const" pointer(opt) direct-declarator ";"

	"char" "const" "*" type-qualifier-list(opt) identifier ";"

	"char" "const" "*" "foo" ";"

The crucial grammar rule is

	declaration-specifiers:
		storage-class-specifier declaration-specifiers(opt)
		type-specifier declaration-specifiers(opt)
		type-qualifier declaration-specifiers(opt)

which allows generation of both "const char" and "char const".

Section A8.6.1 says that type-qualifies which follow the "*" in a pointer
declaration apply to the pointer itself, rather than to the pointed-at
object.  Previous statements and examples about type-qualifiers -- in
which they were placed before the "*" -- indicate that they apply to the
pointed-at objects.

[As an aside, it might be a good idea to obtain the book -- if you
haven't already.  Zot!]

Steve Emmerson        steve@unidata.ucar.edu        ...!ncar!unidata!steve
Technical Details
Message-ID: <5977@ncar.ucar.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!ncar!groucho!steve
References: <25ABBF93.9618@paris.ics.uci.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!ncar!groucho!steve
From: steve@groucho.ucar.edu (Steve Emmerson)
Newsgroups: comp.std.c
Subject: Re: Is `char const *foo;' legal?
Message-ID: <5977@ncar.ucar.edu>
Date: 11 Jan 90 15:29:08 GMT
References: <25ABBF93.9618@paris.ics.uci.edu>
Sender: news@ncar.ucar.edu
Organization: University Corporation for Atmospheric Research (UCAR)
Lines: 45