Article View: comp.std.c
Article #4099Re: Function-prototype scope: Why?
From: John Rickard
Date: Sun, 24 Sep 1995 16:20
Date: Sun, 24 Sep 1995 16:20
48 lines
2734 bytes
2734 bytes
Stan Ryckman (sgr@ae-sun01.alden.com) wrote:
: In article <43ugdt$ihe@newshost.lanl.gov>,
: Tanmoy Bhattacharya <tanmoy@qcd.lanl.gov> wrote:
: >In article <43s7k4$j2v@gatekeeper.atml.co.uk>, jrr@atml.co.uk (John Rickard)
: >writes:
: >|> Stan Ryckman (sgr@ae-sun01.alden.com) wrote:
: >|> : All pointers-to-struct must have the same "shape"
: >|>
: >|> Is that so? I've often written code that makes that assumption, but I
: >|> can't find any justification for it in the standard. Can you give
: >|> references?
:
: It was somewhat beaten to death in this group a while ago, I think,
: as derivable from the standard (though not stated there as such)
: in order to make pointers to incomplete structures work,
(The article by Tanmoy Bhattacharya hasn't arrived here yet, so I may
be missing something.)
It is indeed with pointers to incomplete structures that I have made
the assumption. But where does the standard say -- or even suggest --
that such pointers must `work'?
So far as I can tell from the standard, if struct S is an incomplete
structure type that is never completed in the translation unit, there
are no requirements for the type struct S * to be compatible with, or
have the same representation as, any other type. If (say) char * and
int * have different representations, then the implementation can
(again, so far as I can tell) choose to give struct S * the same
implementation as either of those, or even put absurdly strong
alignment restrictions on never-completed structure types and
represent struct S * in a single byte as the top 8 bits of the
address.
Or is the argument that one can write, say,
file1.c: file2.c:
struct S1; struct S2 { int i; };
knowing secretly, and not telling the compiler, that struct S1 really
has a single member, called `i', of type int? If this is so, then
6.1.2.6 says that struct S1 and struct S2 are compatible types, and so
(by 6.5.4.1) struct S1 * and struct S2 * are compatible types. That
does not seem the most plausible reading of the standard to me (I'd
say that struct S1 had no members), but I suppose it is possible.
--
John Rickard
Technical Details
Message-ID:
<4440gl$htt@gatekeeper.atml.co.uk>Path:
arc1-ca.pugleaf.net!news.atml.co.uk!jrrReferences:
<43cgmb$cec@news0.rain.rg.net> <43qod5$clf@ae-sun01.alden.com> <43s7k4$j2v@gatekeeper.atml.co.uk> <43ugdt$ihe@newshost.lanl.gov> <43urgs$gkd@ae-sun01.alden.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.atml.co.uk!jrr From: jrr@atml.co.uk (John Rickard) Newsgroups: comp.std.c Subject: Re: Function-prototype scope: Why? Date: 24 Sep 1995 16:20:37 GMT Organization: Advanced Telecommunications Modules Ltd, Cambridge, UK. Message-ID: <4440gl$htt@gatekeeper.atml.co.uk> References: <43cgmb$cec@news0.rain.rg.net> <43qod5$clf@ae-sun01.alden.com> <43s7k4$j2v@gatekeeper.atml.co.uk> <43ugdt$ihe@newshost.lanl.gov> <43urgs$gkd@ae-sun01.alden.com> NNTP-Posting-Host: bass.atml.co.uk X-Newsreader: TIN [version 1.2 PL2]