Operating System - HP-UX
1834055 Members
2552 Online
110063 Solutions
New Discussion

What is the different between 32bits and 64bits for data types in C?

 
SOLVED
Go to solution
MA Qiang
Regular Advisor

What is the different between 32bits and 64bits for data types in C?

How to define the data type of 4 bytes integer with 64bits compiler options? and 1 byte char, 4 bytes float...
Where can I find some documents about it?

Best Regards.
3 REPLIES 3
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: What is the different between 32bits and 64bits for data types in C?

The best way to answer your question is to ask the machine itself.

Compiles the attached C program thusly:
cc +DD64 sizes.c -o sizes64
cc +DD32 sizes.c -o sizes32

and then execute each program.

The documentation for this is found under /opt/ansic/html

Here is a quote from one of the .html's that illustrates a good technique for portability.
------------------------------------------
Improving Portability
Type definitions can be used to compensate for differences in C compilers. For example:
#if SMALL_COMPUTER
typedef int SHORTINT;
typedef long LONGINT;

#elif
BIG_COMPUTER
typedef short SHORTINT;
typedef int LONGINT;

#endif
This is useful when writing code to run on two computers, a small computer where an int is two bytes, and a large computer where an int is four bytes. Instead of using short, long, and int, you can use SHORTINT and LONGINT and be assured that SHORTINT is two bytes and LONGINT is four bytes regardless of the machine.

-------------------------------------

I have used a similar technique for many years so that I never use the native types but rather use a typedef'ed version.
If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: What is the different between 32bits and 64bits for data types in C?

Ooops, I missed the sizes.c attachment.

If it ain't broke, I can fix that.
MA Qiang
Regular Advisor

Re: What is the different between 32bits and 64bits for data types in C?

Thank you!