473,395 Members | 1,653 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,395 software developers and data experts.

Size of primitive types platform vs language

14
Hi all,
I am new to programming.I read the following lines:

"Size of primitive types in Java is defined in the language specification, whereas in C and C++ it depends on the platform"

Can somebody explain this clearly?

thanks in advance,
Kishore
Dec 6 '09 #1
4 3110
donbock
2,426 Expert 2GB
In C, a short is at least 16 bits, but it could be more, but it can be no bigger than a long. A long is at least 32 bits, but it could be more. An int is at least as big as a short, but no bigger than a long. There are other rules of this sort. The point is that the C Standard sets minimum sizes for the primitive types and requires certain relationships between their sizes but it deliberately allows compilers to tune the sizes to make best use of the underlying hardware platform.

C++ has similar rules but I don't know if the minimum sizes are precisely the same as for C.
Dec 6 '09 #2
APmore
14
@donbock
many thanks for the good explanation.

......but it deliberately allows compilers to tune the sizes to make best use of the underlying hardware platform.

What is seen in hardware platform to set the sizes of data types?..like opcode size or memory ..?

And what about java?how come its machine independent?

Regards,
Kishore
Dec 6 '09 #3
Banfa
9,065 Expert Mod 8TB
Normally part of the hardware platform that determines these sizes are address bus width, internal register size (and instruction set) and the memory layout. The internal register size and the memory layout are often related to the data bus width.

The register size(instruction set) sets the size of the integer that the platform works best with, that is the integersize it loads and saves quickest and can most easily perform arithmetic on. This often has a direct effect on the size of int in C. The memory layout has a direct effect on the size of char, specifically the number of bits in a char. Finally the address bus width has a direct relation to the size of pointers used in C for the platform.
Dec 6 '09 #4
jfwfmt
11
Java is a language that (0riginally) compiled into byte codes which are opcodes for a specified (non-existant) machine. The machine in implemented in a Java Virtual Machine. This machine has a defined length of the integers, characters .... The idea was write once, run on many different machines with no changes to the byte codes, just to the JVMs.

/s/ Jim WIlliams
Dec 9 '09 #5

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

Similar topics

3
by: Tony Johansson | last post by:
Hello! I'm reading in a document about window system and here they talk about primitive class. So my question is what is a primitive class? It might not mean any spacial just a name of a...
79
by: syntax | last post by:
what is the size of a pointer? suppose i am writing, datatype *ptr; sizeof(ptr); now what does this sizeof(ptr) will give? will it give the size of the
30
by: jimjim | last post by:
Hello, This is a simple question for you all, I guess . int main(){ double *g= new double; *g = 9; delete g; cout<< sizeof(g)<<" "<<sizeof(double)<<" "<<sizeof(*g)<<" "<<*g<<" "<<endl; *g =...
3
by: Bear | last post by:
Hello there How come it's possible to add values of the type "int" into an ArrayList when the Add member function only accepts values of type "object"? Is an int just a "typedef" of the Int32...
14
by: Matt | last post by:
I want to know if "int" is a primitive type, or an object? For example, the following two approaches yield the same result. > int t1 = int.Parse(TextBox2.Text); //method 1 > int t2 =...
1
by: Neil Zanella | last post by:
Hello all, In C and C++ a primitive data type is represented by a minimum number of bits as defined by the corresponding standard. For instance an int is assumed to be at least 16 bits on all...
4
by: Roy | last post by:
I have an object with array of some data types. How do I get the number of bytes for it in managed code? The underlying data types could be primitive types or userdefined structures. For example I...
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...
10
by: Noah Roberts | last post by:
I understand that different integer types might have time penalties because of word boundaries. Where can I get information clarifying this topic? A quick google didn't turn up much for me...nice...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.