🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #1176

Re: struct hack, was Re: strcpy implementation question

#1176
From: Stephen R. van den Berg
Date: Tue, 08 Sep 1992 12:46
39 lines
2289 bytes
Clive Feather writes:
>diamond@jit081.enet.dec.com writes:
>>David Adrien Tanguay writes:
>>>diamond@jit081.enet.dec.com writes:
>>>>Israel Pinkas writes:
>>>>> The variable length struct is a hack.  There is nothing in the language that
>>>>> prevents the compiler from performing bounds checking on accesses to name.
>>>> Bounds checking is not allowed to affect output of a valid but ugly program.
>>> I had the impression that the last time it came up here the conclusion was
>>> that this trick was not sanctioned[...]  3.3.6 "Additive Operators"
>>> says that you aren't guaranteed to go past the end of an array object,
>> No (though it was the conclusion of some others) and yes, respectively.
>> You can't go past the end of an array object.  But if malloc() or some other
>> variable has defined the end of the actual array object, then the + operator
>> can get you that far, regardless of the declared type that some other array
>> variable had before getting flattened to a pointer.

>But there is an intepretation that says that, given

>    int a [5][5];

>the access "a [1][6]" is illegal, because it goes past the bounds of the
>array "a [1]". In other words, the declared type of the array does
>restrict what can happen to a pointer derived from it.

Correct, but:

	int a[5][5]; int*p;

	p=a[1]+5;

	printf("a[2][0]=a[1][6]=%d\n",*++p);

sure seems to be allowed (although not recommended).
-- 
Sincerely,                                  berg@pool.informatik.rwth-aachen.de
           Stephen R. van den Berg (AKA BuGless).    berg@physik.tu-muenchen.de

"And now for something *completely* different!"
Technical Details
Message-ID: <1992Sep8.124655.1498@Urmel.Informatik.RWTH-Aachen.DE>
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!Germany.EU.net!Urmel.Informatik.RWTH-Aachen.DE!physik.tu-muenchen.de!berg
References: <9209040741.AA16120@enet-gw.pa.dec.com> <1992Sep07.104932.20060@x.co.uk>

Show Full Headers
Complete Article Headers
Newsgroups: comp.std.c
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!Germany.EU.net!Urmel.Informatik.RWTH-Aachen.DE!physik.tu-muenchen.de!berg
From: berg@physik.tu-muenchen.de (Stephen R. van den Berg)
Subject: Re: struct hack, was Re: strcpy implementation question
Message-ID: <1992Sep8.124655.1498@Urmel.Informatik.RWTH-Aachen.DE>
Originator: berg@tabaqui
Sender: news@Urmel.Informatik.RWTH-Aachen.DE (Newsfiles Owner)
Nntp-Posting-Host: tabaqui
Organization: Rechnerbetrieb Informatik  /  RWTH Aachen
References: <9209040741.AA16120@enet-gw.pa.dec.com> <1992Sep07.104932.20060@x.co.uk>
Date: Tue, 8 Sep 92 12:46:55 GMT
Lines: 39