A "word" is dependent on CPU-achitecture and compiler-implementation.
I read in R. Stevens "Network Programming" about some reliable length of datatypes: it's not so evident that an int is 16 or 32 bit.
(I think a short is 16, a long is 32 and a int is machine depended...)
Many libraries (particularly network) provide datatyes like int32, to be certain about the length.
Patrick
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2003-01-06
In a 32bit environment/compiler, long is normally 32bits (however it need not be so, simply at least 32bits, and at least as large as int - ANSI C specification).
You can use sizeof() to portably deternine the size of any type, class, struct, array, or instance of any of these.
Also <limits> (or <limits.h> in C) defines macros specifying the min and max values that may be represented by the basic types.
gcc does support long long (at least it does in the ARM cross-compiler version I also use). However, using long long may affect portability.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
hi when i'm compiling with dev cpp long is being allocated only 4 bytes isnt it supposed to allocate 8???
Im a newbie so please bear me....
I did a quick check in my book, long is required to be at least 4 bytes, and at least as big as int. It does not have to be bigger.
In some cases, you can use long long, though I don't remember if that works under gcc, I remember running into some display issues.
I also remember being smarter than I am too.
Wayne
if you can ?, use a double if need be.
check your computer
#include <iostream>
using namespace std;
int main( )
{
cout << sizeof(double) << endl;
system("PAUSE");
return 0;
}
I guess I was presuming that they wanted an integer type, which may have been a false presumption on my part...
Modifying the code you so graciously provided in the service of answering my question about long long:
#include <iostream>
using namespace std;
int main( )
{
cout << sizeof(double) << endl;
cout << sizeof(int) << endl;
cout << sizeof(long) << endl;
cout << sizeof(long long) << endl;
system("PAUSE");
return 0;
}
I find that long long does in fact show up as 8 bytes. I still remember some funnies in getting it displayed or used. He said, scratching his head...
Wayne
Wayne
in my experience:
char=1=BYTE
int=2=WORD
long=4=DWORD
double=8
-yano
ctypes: http://www.sysprog.net/ctype.html
A "word" is dependent on CPU-achitecture and compiler-implementation.
I read in R. Stevens "Network Programming" about some reliable length of datatypes: it's not so evident that an int is 16 or 32 bit.
(I think a short is 16, a long is 32 and a int is machine depended...)
Many libraries (particularly network) provide datatyes like int32, to be certain about the length.
Patrick
In a 32bit environment/compiler, long is normally 32bits (however it need not be so, simply at least 32bits, and at least as large as int - ANSI C specification).
You can use sizeof() to portably deternine the size of any type, class, struct, array, or instance of any of these.
Also <limits> (or <limits.h> in C) defines macros specifying the min and max values that may be represented by the basic types.
gcc does support long long (at least it does in the ARM cross-compiler version I also use). However, using long long may affect portability.