Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!feeder.erje.net!us.feeder.erje.net!news2.arglkargh.de!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Wojtek Lerch Newsgroups: comp.std.c Subject: Re: C11 6.3.2.3p7 Referenced Type Date: Mon, 07 Jan 2013 00:07:20 -0500 Lines: 52 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net QoeyooZurxU3tsVAQqlUxQsO+d3/JGmgmCjRQut0Ebob3cHzm0nndTb3OhaX+8Krlb Cancel-Lock: sha1:BqsdSpOEJRVr1ByxRb/FXnCtPHA= User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/17.0 Thunderbird/17.0 In-Reply-To: Xref: csiph.com comp.std.c:1821 On 06/01/2013 11:30 PM, Shao Miller wrote: > On 1/6/2013 22:13, Wojtek Lerch wrote: >> >> int main( void ) { >> if ( _Alignof(int) <= _Alignof(float) ) { >> float f; >> int n, *p = (int*) &f; >> if ( p == &n ) >> puts( "They're equal!" ); >> } >> } >> >> If this program produces output on some implementation, which >> requirement of the standard does the implementation violate? (Chapter >> and verse please.) ... > If I've followed along correctly, the question is: Is a converted > pointer defined to point to the same object as the original, or only the > result of its conversion back to the original pointer type? Yes. And if it's the first one, then where does the standard say it? > I don't see why this example should be prohibited. > 'n' is never > accessed, so an implementation could choose to put it in the same place > where 'f' is. The implementation is free to completely optimize them out and not put them anywhere at all, but that does not change the fact that in the abstract machine their addresses must be different. If I changed the check to "if ( (char*)&f == (char*)&n )", it would be required to return false, regardless of whether f and n are accessed or not. Of course, any decent implementation will generate the same code that it would if I wrote if(0), without any actual comparing of addresses at runtime. How about this then: float f; int n, *p = (int*) &f; char *x = (char*)&f, *y = (char*) p; if ( x != y ) ... In other words, does the standard guarantee that (char*)(int*)&x, if defined, must be equal to (char*)&x? > As an implementation, I'd enjoy that kind of freedom, for > conservation of storage. Sure, as long you follow the observable behaviour of the abstract machine. In the abstract machine, n and f are distinct objects and they don't overlap.