delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/08/20/21:33:40

From: Erik Max Francis <max AT alcyone DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Why does sizeof give me...
Date: Sat, 16 Aug 1997 22:03:14 -0700
Organization: Alcyone Systems
Lines: 40
Message-ID: <33F68612.5EF83660@alcyone.com>
References: <97Aug13.151644gmt+0100 DOT 17061 AT internet01 DOT amc DOT de>
NNTP-Posting-Host: newton.alcyone.com
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Chris Croughton wrote:

> I have used one compiler (VAX, possibly?) which had short = int = long
> and
> all 32 bit.

This is ANSI C compliant, believe it or not.

> Fortunately, char was still 8 bit (but it needn't be - some
> machines have 9 bit chars).

Yes, which is pretty bizarre.  Strangely enough, though, the guaranteed
limitations on int short long are that short will be at least 16 _bits_
and long will be at least 32 _bits_, independent of the number of bits in
a char (ANSI C 5.2.4.2).  Note also that you can't have architectures with
_less_ than 8 bits from ANSI C.

> The only portable way is to do it yourself - either by breaking longer
> variables up into chars or in ASCII.  Especially since you can't rely
> on any byte ordering scheme (I gather there are some machines where a
> long is held in memory as bytes 2, 1, 4 and 3 or something similar, not
> even a reversible format).

I don't know offhand, but my understanding is that ANSI C doesn't make any
determination of the internal respresentation of the bytes in a multi-byte
integral type (short, int, long).  I imagine that there aren't any such
arbitrary architectures that aren't either little- or big-endian.

> Isn't this all in the FAQ?  Or was it one of the other C newsgroup FAQs?

I believe some of the issues are mentioned in the comp.lang.c FAQ, but I
doubt it's addressed in the DJGPP FAQ.

-- 
       Erik Max Francis, &tSftDotIotE / email / mailto:max AT alcyone DOT com
                     Alcyone Systems /   web / http://www.alcyone.com/max/
San Jose, California, United States /  icbm / 37 20 07 N  121 53 38 W
                                   \
   "Love is not love which alters / when it alteration finds."
                                 / William Shakespeare, _Sonnets_, 116

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019