Article View: comp.std.c
Article #4292Re: Variable length struct hack
From: Thad Smith
Date: Sat, 28 Oct 1995 05:48
Date: Sat, 28 Oct 1995 05:48
24 lines
1178 bytes
1178 bytes
In article <46qm6e$bba@rdsunx.crd.ge.com>,
volpe@bart.crd.ge.com (Christopher R. Volpe) wrote:
>In article <DH220v.9r@thinkage.on.ca>, dat@thinkage.on.ca (David Adrien Tanguay) writes:
>>How is the following concept for strict conformance? (with appropriate context)
>>
>>struct s_t {
>> int this, that;
>> /* this structure has a variable length tail */
>>};
>>
>>#define tail_of(p) ((char*) ((p)+1))
>>
>>void f(size_t tail_size) {
>> struct s_t *sp = malloc(sizeof(*sp) + tail_size);
>> char *the_tail_is = tail_of(sp);
...
>>If tail_size < sizeof(struct s_t), can tail_of() fail because of the +1?
>Correct.
Why? ANSI Classic 3.3.6 explicitly allows a pointer to be one past
the last element.
Thad
Technical Details
Message-ID:
<BMckwQ9ythGC084yn@csn.net>Path:
arc1-ca.pugleaf.net!teal.csn.net!not-for-mailReferences:
<463egk$jbb@nntp.Stanford.EDU> <DH0uG2.Ft@eskimo.com> <DH220v.9r@thinkage.on.ca> <46qm6e$bba@rdsunx.crd.ge.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!teal.csn.net!not-for-mail From: thads@csn.net (Thad Smith) Newsgroups: comp.std.c Subject: Re: Variable length struct hack Date: 27 Oct 1995 23:48:47 -0600 Organization: T3 Systems Distribution: world Message-ID: <BMckwQ9ythGC084yn@csn.net> References: <463egk$jbb@nntp.Stanford.EDU> <DH0uG2.Ft@eskimo.com> <DH220v.9r@thinkage.on.ca> <46qm6e$bba@rdsunx.crd.ge.com> Reply-To: ThadSmith@acm.org NNTP-Posting-Host: 199.117.27.22