F
Flash Gordon
Richard Heathfield wrote, On 12/09/07 09:21:
Yes, but if you know this and have good reasons this is not a problem
just a known limitation.
I've worked on systems where CHAR_BIT is 16 and the processor has a 16
bit address bus and some of the address space allocated by the processor
manufacturer for special purposes. So your array is *guaranteed* not to fit.
So you are allowed to ignore the portability issues that do not affect
you but those who have different portability requirements are not
allowed to limit themselves to the implementations of interest to you?
I've had very good reasons to limit myself to implementations which
support a 16 bit integer type with no padding, and at the time I *knew*
that there were implementations with no type smaller than 24 bits. My
employer would not have been pleased if I spent extra time making it
portable to implementations it was *very* unlikely to be ported to.
Ian Collins said:
Yes, of course. C99 makes it not only possible but easy to write such
code. Not only does the use of C99 features render your code
non-portable to C90 implementations, but it can even render your code
non-portable to *other C99 implementations*.
Yes, but if you know this and have good reasons this is not a problem
just a known limitation.
This is true of C90, too, but in a much more limited way. For example, I
have occasionally had cause to define an array of UCHAR_MAX + 1
unsigned long ints, which seems perfectly unobjectionable and indeed is
quite okay on what you might call "normal" implementations - but on
reflection it's easy to see how it could break. If CHAR_BIT is 32, say,
then that array is suddenly rather on the large side.
I've worked on systems where CHAR_BIT is 16 and the processor has a 16
bit address bus and some of the address space allocated by the processor
manufacturer for special purposes. So your array is *guaranteed* not to fit.
So one must exercise care even in C90 (or accept that one's code is not
portable to certain kinds of implementation). C99 has all of the C90
portability issues, and adds a whole bunch of new ones.
So you are allowed to ignore the portability issues that do not affect
you but those who have different portability requirements are not
allowed to limit themselves to the implementations of interest to you?
I've had very good reasons to limit myself to implementations which
support a 16 bit integer type with no padding, and at the time I *knew*
that there were implementations with no type smaller than 24 bits. My
employer would not have been pleased if I spent extra time making it
portable to implementations it was *very* unlikely to be ported to.