Mailing List Archive

Support open source code!


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

tlug: 64 bit int



>>>>> "Darren" == Darren Cook <darren@example.com> writes:

    >> For practical purposes (ie, working with existing code), int is
    >> 32 bits.  Architectures with 64 bit ints do exist, of course
    >> (Alpha and I believe UltraSparc come to mind; purging ports of
    >> the int = 32 bits assumption is a regular complaint of Alpha
    >> programmers)

    Darren> I write lots of code with the assumption that short is 16
    Darren> bits and int and long are 32 bits. Doesn't gcc have "long
    Darren> long" for 64-bit integers?

    Darren> What is the portable-to-64 way of referring to 16 and 32
    Darren> bit integers?

AFAIK there isn't one.  Last I looked (a long time ago; ANSI standard
was still "draft"), the standard says only

		  8 <= char <= short <= int <= long
				 and
			      32 <= long

and "long long" is a GCC extension.  Where it matters (mostly "on the
wire", ie, in the network protocols themselves) X11 uses its own types
like CARD8, CARD16, and CARD32 to guarantee specific sizes.  These are 
then conditionally included like this

#ifdef ArchitectureX86
typedef unsigned char CARD8
typedef unsigned short int CARD16
typedef unsigned int CARD32
#elsif ArchitectureM68xxx

(the actual strategy used is more complex).  Linux itself uses __u8,
__s32, and the like (as well as abbreviations without the leading
`__', but _only_ in the kernel); see /usr/include/asm/types.h.  Try
comparing the versions in /usr/src/include/asm-alpha/types.h and
/usr/src/include/asm-i386/types.h.  (Oops, turns out that on Alpha an
int is 32 bits; in 64-bit compilers, long and long long are 64 bits,
on 32-bit compilers, long long is 64, but long is 32.)

-- 
University of Tsukuba                Tennodai 1-1-1 Tsukuba 305-8573 JAPAN
Institute of Policy and Planning Sciences        Tel/fax: +1 (298) 53-5091
__________________________________________________________________________
__________________________________________________________________________
What are those two straight lines for?  "Free software rules."
---------------------------------------------------------------
Next Nomikai: 20 November, 19:30 Tengu TokyoEkiMae 03-3275-3691
Next Meeting: 12 December, 12:30 Tokyo Station Yaesu central gate
---------------------------------------------------------------
Sponsor: PHT, makers of TurboLinux http://www.pht.co.jp


Home | Main Index | Thread Index

Home Page Mailing List Linux and Japan TLUG Members Links