Re: ANSI requirement

[email protected] (karl williamson)
Newsgroups perl.perl5.porters
Message-ID <[email protected]>
Zefram wrote:
> ??var Arnfj??r?? Bjarmason wrote:
>> I vaguely recall someone mentioning that we rely on some features of C
>> that aren't strictly guaranteed by ANSI C,
> 
> Yes, we do.
> 
>>                                           such as the the offset into
>> a struct being the sum of the sizeof() of the struct members that came
>> before in the struct.
> 
> But not this particular one, which is almost never true across a whole
> implementation.  It would require that no data types have any alignment
> requirement.  Implementations almost always use padding in structs.
> There is something similar, though: we do rely on the offset of a struct
> member being *a pure function of* the types of the preceding members.
> (That is, that where two structs begin with type-identical sequences
> of members, the layouts of those members will be compatible.)  This is
> almost always true.
> 
> We rely on a few other things that are almost always true but not
> guaranteed by the standards.  Off the top of my head:
> 
> * that all data pointers have bitwise-compatible representations
> 
> * that function pointers are the same size as data pointers
> 
> * that signed integers are represented in twos-complement
> 
> * that signed integer arithmetic cleanly wraps on overflow
> 
> * that the bits of multi-byte integers are divided up into bytes in
>   adjacent groups, with all bits of each byte participating in the
>   integer representation
> 
> * that bytes consist of exactly eight bits

We do test that bytes are 8 bits in Configure.
> 
> * that all-bits-zero is a valid representation of a null pointer
> 
> -zefram
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.