Re: code portability
- From: Andrew Poelstra <apoelstra@xxxxxxxxxx>
- Date: Fri, 04 Aug 2006 06:19:23 GMT
On 2006-08-04, Ian Collins <ian-news@xxxxxxxxxxx> wrote:
Andrew Poelstra wrote:
On 2006-08-03, Keith Thompson <kst-u@xxxxxxx> wrote:
Richard Heathfield <invalid@xxxxxxxxxxxxxxx> writes:
The introduction of long long int was, in my continued opinion, a mistake.
All the ISO guys had to do was - nothing at all! Any implementation that
wanted to support 64-bit integers could simply have made long int rather
longer than before - such a system would have continued to be fully
conforming to C90. And if it broke code, well, so what? Any code that
wrongly assumes long int is precisely 32 bits is already broken, and needs
fixing.
That's true, but 64 bits is the effective limit for this. The
following:
char 8 bits
short 16 bits
int 32 bits
long 64 bits
is a reasonable set of types, but if you go beyond that to 128 bits,
you're going to have to leave gaps (for example, there might not be
any 16-bit integer type).
1) This isn't really a problem; you can use a 32-bit variable to store
16-bit values; if you really need 16 bits you might need some debug
macros to artificially constrain the range.
Just beware of overflows!
Yes, that would require more than debug macros to fix, since you'd want
the overflow behavior to be the same whether or not you are debugging!
(It's a bit of a pain, I admit, but there aren't too many times when you
absolutely need an exact number of bits.)
2) If you've got a 128-bit processor, IMHO, you shouldn't be insistingUnless your (possibly externally imposed) data happens to be 8 bit.
on using 8-bit types. That just sounds inefficient. [OT]
If I were ISO, I'd consider adding a new specifier to scanf and friends
to read a specified number of bytes (or probably bits, although that
could be a lot harder to implement) into an already defined type. So, if
you wanted to read 8 bits into an int (which is 32 bits on this particular
system), you'd do:
fscanf (fhandle, "%d8b", &charvar);
Since I'm not ISO, nor will they create such a change, I'd stick to
avoiding arbitrary data widths (in general, stick with text files as
long as you can spare the space), and don't worry about changing data
widths: most companies don't switch compilers too often.
If you have Data of a Certain Width imposed on you, you're probably
going to have to fiddle with stuff when changing compilers anyway,
so suddenly having long twice as wide should be an expected problem.
--
Andrew Poelstra <http://www.wpsoftware.net/projects>
To reach me by email, use `apoelstra' at the above domain.
"Do BOTH ends of the cable need to be plugged in?" -Anon.
.
- Follow-Ups:
- Re: code portability
- From: Richard
- Re: code portability
- References:
- code portability
- From: Eigenvector
- Re: code portability
- From: websnarf
- Re: code portability
- From: Malcolm
- Re: code portability
- From: Keith Thompson
- Re: code portability
- From: Richard Heathfield
- Re: code portability
- From: Keith Thompson
- Re: code portability
- From: Andrew Poelstra
- Re: code portability
- From: Ian Collins
- code portability
- Prev by Date: granularity of size of operator
- Next by Date: Re: granularity of size of operator
- Previous by thread: Re: code portability
- Next by thread: Re: code portability
- Index(es):
Relevant Pages
|