number of bytes for a type in C++

J

jrefactors

In C++, the amount of memory used to store int is 4 bytes, or dependent
upon the hardware?
I think still dependent on the machine, since C++ compiler is platform
dependent.

Please advise. Thanks
 
J

JH Trauntvein

I believe that the standard guarantees minimum ranges for intrinsic
types. For example, I believe that the minimum range for type int is
[-32768, +32767].

Regards,

Jon Trauntvein
 
V

Victor Bazarov

In C++, the amount of memory used to store int is 4 bytes, or dependent
upon the hardware?
I think still dependent on the machine, since C++ compiler is platform
dependent.

You think right.
 
P

pvinodhkumar

It is depending upon the hardware.

According to TCPPPL,
this is what guaranteed about the sizes of fundamental types

1 = sizeof(char) <= sizeof(short) <= sizeof(int) <=sizeof(long)
1<= sizeof(bool) <= sizeof(long)
sizeof(char) <=sizeof(wchar_t) <= sizeof(long)
sizeof(float) <= sizeof(double) <= sizeof(long double)
sizeof(N) = sizeof(signed N) = sizeof(unsigned N)
 
K

Keith Thompson

In C++, the amount of memory used to store int is 4 bytes, or dependent
upon the hardware?
I think still dependent on the machine, since C++ compiler is platform
dependent.

In C, it's dependent on the implementation, with some specific
constraints imposed by the standard.

But since your question is about C++, cross-posting it to comp.lang.c
was a bad idea.

Followups redirected.
 
R

Rolf Magnus

Keith said:
In C, it's dependent on the implementation, with some specific
constraints imposed by the standard.

The same is true for C++. The rules regarding integer type sizes are the
same in C++ as in C, with the exception that C++ doesn't know the "long
long" type.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top