473,407 Members | 2,320 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Definition of 'int' on different platforms.

I know on some operating systems, an int is the same as a short, while on others, an int is the same as a long. It depends on the word size of the operating system.

Does anybody know what the definition of int in C is for linux, windows, cygwin etc?
Jan 9 '09 #1
5 4652
Banfa
9,065 Expert Mod 8TB
You have related int size to operating system, however it is actually related to platform. The platform is mainly dependent on the processor used in the system, although other bits of hardware and how the hardware is put together can also be relevant, however it isn't unusual for these OS to also play a part.

On most PCs for most 32 and 64 bit versions of the operating systems you mention int is 4 bytes (New versions of Windows, Windows pre Win95 had 16 bit ints). That does not mean that int will necessarily be that size on all platforms using those operating systems, particularly embedded versions running on non-intel platforms.
Jan 9 '09 #2
gpraghuram
1,275 Expert 1GB
I think now all 32 bit compilers the size of int is 32 bit.

Raghu
Jan 9 '09 #3
donbock
2,426 Expert 2GB
The Standard requires that "int" be no smaller than "short" and no bigger than "long". It is allowed to be any size in between. Implementations are encouraged to select a size for "int" that is the most efficient for the platform. Notice that different compiler vendors for the same platform might disagree on what that most efficient size is.

The answer to your question can be found in <limits.h>. Macros can be found there that specify the minimum and maximum values supported by "int", "short", and "long".

You might be able to get your answers merely by examining <limits.h>; however, your compiler might have many levels of nested headers or conditional compilation options to make it hard to interpret. You could write a simple program that prints out all of the relevant limits.
Jan 9 '09 #4
Banfa
9,065 Expert Mod 8TB
In general the C standard requires that

sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long)

C++ also makes this requirement but additionally requires that

short and int are least 16 bits in size and long is at least 32 bits.

This allows you to make some assumptions in C++ that you can't make in C (which actually makes writing completely portable code easier).
Jan 9 '09 #5
JosAH
11,448 Expert 8TB
C does the same, i.e. the limits.h file specifies the minimal maximum int values and the maximal minimum int values of several sizes (short, normal and long). In C an int takes at least 2 octets and a long takes at least 4 octets.

kind regards,

Jos
Jan 9 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: DanielBradley | last post by:
Hello all, I have recently been porting code from Linux to cygwin and came across a problem with static const class members (discussed below). I am seeking to determine whether I am programming...
10
by: Kobu | last post by:
My question is about the use and meaning of the terms "declaration" and "definition" as it pertains to the C language. I've read sources that mix the two up when talking about such things as...
8
by: Bryan Parkoff | last post by:
int has two bytes or four bytes. long has four bytes or eight bytes. I can't be sure to choose int or long keyword because I don't trust to get the wrong size. I always check by using...
134
by: jacob navia | last post by:
Hi Suppose you have somewhere #define BOOL int and somewhere else typedef BOOL int;
78
by: Frederick Gotham | last post by:
On modern 32-Bit PC's, the following setup is common: char: 8-Bit short: 16-Bit int: 32-Bit long: 32-Bit "char" is commonly used to store text characters. "short" is commonly used to store...
9
by: linyanhung | last post by:
A int in memory takes 32bits (4 bytes). But if I use ofstream to save a int like this: int i=1234567890; ofstream ofs("c:\\intdata.bin", ios::binary); ofs<<i; It becomes 10 bytes in a...
9
by: Jess | last post by:
Hello, I was told that if I declare a static class constant like this: class A{ static const int x = 10; }; then the above statement is a declaration rather than a definition. As I've...
2
by: Laurent Deniau | last post by:
I would like to know why the following small program does not compile (checked with gcc 4.1.2) and if the compiler behavior is correct: struct A; typedef void (T)(struct A*); void f(void) {...
275
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.