Vladislav Vaintroub
Vladislav Vaintroub

Reputation: 5653

Modern operating system / compiler where int (in C) is not 32 bits?

The question is actually somewhat broader.

Based on the last 15 years experience I currently assume that size of types is as follows:

byte = 8 bit

short = 2 bytes

int = 4 bytes

long long = 8 bytes

Is there a modern OS where this assumption can be challenged?

Upvotes: 11

Views: 801

Answers (5)

Andrey Regentov
Andrey Regentov

Reputation: 3737

You have pretty much platforms (especially in embedded) where it is not. You e.g. can have 2-octet char.

Upvotes: 0

Michas
Michas

Reputation: 9428

There is probably one exception.

long long = error

I've heard there are problems with old Microsoft C compilers. I've seen some workarounds in source code. However Microsoft 32-bit C/C++ Optimizing Compiler Version 16 (from Visual Studio 2010) do have long long.

Upvotes: 0

Raymond Chen
Raymond Chen

Reputation: 45173

Whether or not such "modern" systems exist, you should static_assert assert those assumptions in your code so that if your code is ever ported to a platform where the assumption is incorrect, the person doing the porting will be alerted to the problem immediately.

Upvotes: 4

Joe
Joe

Reputation: 42607

The standard is intentionally vague on this subject, only specifying:

  • C90: sizeof(short) <= sizeof(int) <= sizeof(long)

  • C99: sizeof(short) <= sizeof(int) <= sizeof(long) <= sizeof(long long)

Furthermore, C99 only requires that int be at least a 16-bit value.

Also, 'byte' is not a C datatype.

Upvotes: 3

MK.
MK.

Reputation: 34537

According to this Unicos has int as 64bit. Of course the definition of a "modern" compiler is pretty vague. You can still buy Borland C++ for MS DOS and have your ints are 16bit, but is that modern?

Upvotes: 0

Related Questions