2003-08-25 19:13:27

by Herbert Poetzl

[permalink] [raw]
Subject: [OT] sizeof C types ...


Hi Everyone!

this time not sooo off topic but ...

anyway, ist there some kind of overview how
large the basic C types are on the different
architectures Linux runs on?

char, short, int, long, long int, long long, ...

TIA,
Herbert


2003-08-25 19:33:52

by Randy.Dunlap

[permalink] [raw]
Subject: Re: [OT] sizeof C types ...

On Mon, 25 Aug 2003 21:13:39 +0200 Herbert P?tzl <[email protected]> wrote:

|
| Hi Everyone!
|
| this time not sooo off topic but ...
|
| anyway, ist there some kind of overview how
| large the basic C types are on the different
| architectures Linux runs on?
|
| char, short, int, long, long int, long long, ...

>From gcc mailing list today: <quote>

All GCC targets (except perhaps some specialized targets for certain DSPs
and microcontrollers) support 64-bit integers.

Almost all GCC targets are either "ILP32" or "LP64".

For ILP32:
short is 16 bits
int, long, pointers are 32 bits
"long long" is 64 bits

For LP64:
short is 16 bits
int is 32 bits
long, pointers, and "long long" are 64 bits

None of this requires a specific version, as all these types have been
around for a long time.
</quote>

Also see Ch. 10 of the LDD book:
http://www.xml.com/ldd/chapter/book/ch10.html

--
~Randy [mantra: Always include kernel version.]
"Everything is relative."

2003-08-25 19:27:23

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [OT] sizeof C types ...

> char,

8 bits

> short,

16 bits

> int,

32 bits

> long,

either 32 or 64 bits

> long int,

dito. long is just the short form of long int

> long long, ...

64 bits

2003-08-25 19:44:32

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [OT] sizeof C types ...

On Mon, Aug 25, 2003 at 12:29:06PM -0700, Randy.Dunlap wrote:
> Also see Ch. 10 of the LDD book:
> http://www.xml.com/ldd/chapter/book/ch10.html

Well, that chapter has some issue. It talks of sparc64 when actually
meaning a sparc32 userland on sparc64, and it missed the 2.6 merge of
mips64 into mips as mips can now have either 32 or 64bit longs and
pointers.

2003-08-25 19:39:31

by Herbert Poetzl

[permalink] [raw]
Subject: Re: [OT] sizeof C types ...

On Mon, Aug 25, 2003 at 08:27:21PM +0100, Christoph Hellwig wrote:
> > char,
>
> 8 bits
>
> > short,
>
> 16 bits
>
> > int,
>
> 32 bits
>
> > long,
>
> either 32 or 64 bits
>
> > long int,
>
> dito. long is just the short form of long int
>
> > long long, ...
>
> 64 bits

thanks, almost figured that, but I'm looking for
a tabular info where the different architectures
are present like the folowing:

i386 | ia64 | alpha | sparc | wossname ...
-----------+-------+------+-------+-------+-------------------
char | 8 | | | |
short | 16 | | | |
int | 32 | | | |
long | 32 | | | |
long long | 64 | | | |

best,
Herbert

> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/

2003-08-25 19:40:57

by Herbert Poetzl

[permalink] [raw]
Subject: Re: [OT] sizeof C types ...

On Mon, Aug 25, 2003 at 12:29:06PM -0700, Randy.Dunlap wrote:
> On Mon, 25 Aug 2003 21:13:39 +0200 Herbert P?tzl <[email protected]> wrote:
>
> |
> | Hi Everyone!
> |
> | this time not sooo off topic but ...
> |
> | anyway, ist there some kind of overview how
> | large the basic C types are on the different
> | architectures Linux runs on?
> |
> | char, short, int, long, long int, long long, ...
>
> >From gcc mailing list today: <quote>
>
> All GCC targets (except perhaps some specialized targets for certain DSPs
> and microcontrollers) support 64-bit integers.
>
> Almost all GCC targets are either "ILP32" or "LP64".
>
> For ILP32:
> short is 16 bits
> int, long, pointers are 32 bits
> "long long" is 64 bits
>
> For LP64:
> short is 16 bits
> int is 32 bits
> long, pointers, and "long long" are 64 bits
>
> None of this requires a specific version, as all these types have been
> around for a long time.
> </quote>
>
> Also see Ch. 10 of the LDD book:
> http://www.xml.com/ldd/chapter/book/ch10.html

ahh there is the tabular I was looking for ...

many thanks,
Herbert

> --
> ~Randy [mantra: Always include kernel version.]
> "Everything is relative."
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/

2003-08-25 19:55:54

by Herbert Poetzl

[permalink] [raw]
Subject: Re: [OT] sizeof C types ...

On Mon, Aug 25, 2003 at 08:44:26PM +0100, Christoph Hellwig wrote:
> On Mon, Aug 25, 2003 at 12:29:06PM -0700, Randy.Dunlap wrote:
> > Also see Ch. 10 of the LDD book:
> > http://www.xml.com/ldd/chapter/book/ch10.html
>
> Well, that chapter has some issue. It talks of sparc64 when actually
> meaning a sparc32 userland on sparc64, and it missed the 2.6 merge of
> mips64 into mips as mips can now have either 32 or 64bit longs and
> pointers.

hmm, good to know :( ... isn't this tracked somewhere?
guess it would be an interesting table, especially regarding
the more exotic architectures like arm, cris, s390 ...

what do you think?

best,
Herbert

> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at http://www.tux.org/lkml/

2003-08-25 21:19:53

by J.A. Magallon

[permalink] [raw]
Subject: Re: [OT] sizeof C types ...


On 08.25, Christoph Hellwig wrote:
> > char,
>
> 8 bits
>
> > short,
>
> 16 bits
>
> > int,
>
> 32 bits
>
> > long,
>
> either 32 or 64 bits
>
> > long int,
>
> dito. long is just the short form of long int
>
> > long long, ...
>
> 64 bits
>

If you don't go away from linux, OK.

Really:
char = 8bit
long int = 32 or 64, depending on arch
long long = 64 bits

int = ??? almost anything, depending on arch and compiler.
Run DOS on your P4, with an old compiler, and int defaults to 16 bits.
I think the same also happens for Win16.

int is defined ad the native word size of the hardware+OS.

--
J.A. Magallon <[email protected]> \ Software is like sex:
werewolf.able.es \ It's better when it's free
Mandrake Linux release 9.2 (Cooker) for i586
Linux 2.4.22-rc3-jam1m (gcc 3.3.1 (Mandrake Linux 9.2 3.3.1-1mdk))

2003-08-25 22:10:35

by Zwane Mwaikambo

[permalink] [raw]
Subject: Re: [OT] sizeof C types ...

On Mon, 25 Aug 2003, J.A. Magallon wrote:

> If you don't go away from linux, OK.
>
> Really:
> char = 8bit
> long int = 32 or 64, depending on arch

Well then you can argue that 'long int' is 32bit on 64bit platforms on
Windows (the Windows API dictates LLP64) </pedantry>

> long long = 64 bits
>
> int = ??? almost anything, depending on arch and compiler.
> Run DOS on your P4, with an old compiler, and int defaults to 16 bits.
> I think the same also happens for Win16.
>
> int is defined ad the native word size of the hardware+OS.

2003-08-25 22:37:13

by Erik Andersen

[permalink] [raw]
Subject: Re: [OT] sizeof C types ...

On Mon Aug 25, 2003 at 09:38:37PM +0200, Herbert P?tzl wrote:
> thanks, almost figured that, but I'm looking for
> a tabular info where the different architectures
> are present like the folowing:
>
> i386 | ia64 | alpha | sparc | wossname ...
> -----------+-------+------+-------+-------+-------------------
> char | 8 | | | |
> short | 16 | | | |
> int | 32 | | | |
> long | 32 | | | |
> long long | 64 | | | |

If one cares about the exact number of bits, IMHO one should be
using stdint.h, as defined by ISO-IEC-9899-1999 (C99), section
7.18 Integer types.

Using type such as int8_t, int16_t, int32_t, int64_t, and
uint8_t, uint16_t, uint32_t, uint64_t are the One True Way of
reliably, portably, getting the number of bits you want. It
would be very nice if the kernel were converted to use these
types as well. It would also be nice if every architecture
properly supported C99. Unfortunately, that is not true on
either count. For example, if you want your code to interoperate
with windoz, you will want to do something such as....

#if defined(_WIN32) || defined(__WIN32__)
# define uint8_t unsigned __int8
# define uint16_t unsigned __int16
# define uint32_t unsigned __int32
# define uint64_t unsigned __int64
# define int8_t __int8
# define int16_t __int16
# define int32_t __int32
# define int64_t __int64
#else
# include <stdint.h>
#endif

-Erik

--
Erik B. Andersen http://codepoet-consulting.com/
--This message was written using 73% post-consumer electrons--

2003-08-26 07:30:43

by Christoph Hellwig

[permalink] [raw]
Subject: Re: [OT] sizeof C types ...

On Mon, Aug 25, 2003 at 11:19:50PM +0200, J.A. Magallon wrote:
> If you don't go away from linux, OK.

He specificy asked for Linux...