Article View: comp.std.c
Article #4081Re: Function-prototype scope: Why?
From: Stan Ryckman
Date: Fri, 22 Sep 1995 17:24
Date: Fri, 22 Sep 1995 17:24
48 lines
2341 bytes
2341 bytes
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, but
Tanmoy writes...
>I think the statement is strictly true only if one makes the assumption that
>the linkers are not incredibly smart. All proofs I have seen are based on
>translation units containing incomplete struct pointers (which, by the way
>are not incomplete types): and in the absence of smart linkers, all struct
^^^^^^^^^^^^^^^^^^^^
(That's why I'm using the term "pointer to incomplete struct")
>pointers need to be the same shape for things to work.
The following seems legal [is it? gcc likes it] but not handleable
by a linker however smart unless "shape" is known:
struct S;
struct cs { char c; };
struct is { int i; };
void bar(struct cs*);
void baz(struct is*);
void foo( int is_cs, struct S *inc)
{
is_cs ? bar((struct cs *)inc) : baz((struct is *)inc);
}
In other words, if casting a (pointer to incomplete struct) to
(pointer to some other struct type) is legal, then more than linker
issues are involved, I think.
(Of course, "proofs" derived from inferences from the standard
must assume arbitrarily smart linkers, at least in this group :-)
Cheers,
Stan.
--
HELP! I'M BEING HELD PRISONER IN A .SIGNATURE FACTORY!
Stan Ryckman sgr@alden.com
Technical Details
Message-ID:
<43urgs$gkd@ae-sun01.alden.com>Path:
arc1-ca.pugleaf.net!alden.com!not-for-mailReferences:
<43cgmb$cec@news0.rain.rg.net> <43qod5$clf@ae-sun01.alden.com> <43s7k4$j2v@gatekeeper.atml.co.uk> <43ugdt$ihe@newshost.lanl.gov>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!alden.com!not-for-mail From: sgr@ae-sun01.alden.com (Stan Ryckman) Newsgroups: comp.std.c Subject: Re: Function-prototype scope: Why? Date: 22 Sep 1995 13:24:44 -0400 Organization: Amber & Sneakers Fan Club Message-ID: <43urgs$gkd@ae-sun01.alden.com> References: <43cgmb$cec@news0.rain.rg.net> <43qod5$clf@ae-sun01.alden.com> <43s7k4$j2v@gatekeeper.atml.co.uk> <43ugdt$ihe@newshost.lanl.gov> NNTP-Posting-Host: ae-sun01.alden.com