develooper Front page | perl.perl5.porters | Postings from June 2010

Re: ANSI requirement

Thread Previous | Thread Next
June 12, 2010 04:19
Re: ANSI requirement
Message ID:
Aaron Crane wrote:
>Programs containing this construct are *not* considered to be
>strictly-conforming ANSI/ISO C; Dennis Ritchie has allegedly referred
>to the technique as "unwarranted chumminess with the C implementation"

This is all true, but the struct hack does not have the same dubiousness
as the other things mentioned, such as assuming twos complement.
Not only does the struct hack in practice work everywhere, but AFAIK
no one has ever established hypothetical semantics for a compiler that
would conform to the C standard but on which the struct hack would
not work.  The implicit downgrading of arrays to pointers means that
foo->buf is actually a pointer to foo->buf[0], and doing arithmetic
with this pointer to point outside the struct *is* legal.  Since this
is actually how array indexing works in C, it appears that it would
not be legal for the compiler to impose bounds checking in this case.
So while the struct hack is not unambiguously legal, no one's actually
shown it to be illegal either.

>                                      If someone were interested, I
>think a little configure probing and preprocessor macrology could
>arrange for C99-capable compilers to use flexible array members in
>place of the struct hack in the Perl source.

More fuss than it's worth.  If you can't rely on the flexible array
feature, you might as well just use the struct hack exclusively.
It's never going to not work.


Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About