-
November 13th, 2009, 07:53 AM
#16
Re: What is C++ equipvalent of Java Long?
I had a thread about a month ago about which is more important, what a compiler does, or the standards. It was about half and half, if you're like me, you care more about the compiler than standards. I always add these few lines of code at the beginning of any code that I write
Code:
ASSERT(sizeof(char) == 1, "Replace chars with 8 bit primitive");
ASSERT(sizeof(short) == 2, "Replace shorts with 16-bit primitive");
ASSERT(sizeof(int) == 4, "Replace int with 32-bit primitive");
ASSERT(sizeof(long) == 4, "Replace long with 32-bit primitive");
ASSERT(sizeof(long long) == 8, "Replace long long with 64-bit primitive");
ASSERT(sizeof(float) == 4, "Replace float with 32-bit primitive");
ASSERT(sizeof(double) == 8, "Replace double with 64-bit primitive");
ASSERT(sizeof(long double) == 12, "Replace long double with 96-bit primitive");
That way if I port my code to a platform or compiler that has a difference, I can do a quick bulk replace of the primitive that doesn't match up to what I expect
I have a huge header file full of those things for large projects, especially since I use cross-platform libraries that may be built differently, specifically wxWidgets.
-
November 13th, 2009, 08:18 AM
#17
Re: What is C++ equipvalent of Java Long?
Originally Posted by monarch_dodra
Isn't that the definition of a byte though? The smallest element a processor can manipulate?
Byte is one of many computer terms with a modified meaning.
In the early days of computing, thats correct. And it was common to find such things as 7 bit bytes. In modern times anyone refering to a byte as anything other than an octect is asking to be misunderstood.
Signature
Please use: [ code ][/ code ] tags and reasonably correct tabbing. They really help us read your code
End Signature
-
November 13th, 2009, 08:51 AM
#18
Re: What is C++ equipvalent of Java Long?
Originally Posted by ictoan
Hello!
Is long returned by n.longValue() the same as long (signed) in C++?
Documents on value returned after use of Number class's longValue is required
On 32bit systems, long long is defined as a size of 8 bytes
-
November 13th, 2009, 04:53 PM
#19
Re: What is C++ equipvalent of Java Long?
Originally Posted by ninja9578
I had a thread about a month ago about which is more important, what a compiler does, or the standards. It was about half and half, if you're like me, you care more about the compiler than standards. I always add these few lines of code at the beginning of any code that I write
Code:
ASSERT(sizeof(char) == 1, "Replace chars with 8 bit primitive");
ASSERT(sizeof(short) == 2, "Replace shorts with 16-bit primitive");
ASSERT(sizeof(int) == 4, "Replace int with 32-bit primitive");
ASSERT(sizeof(long) == 4, "Replace long with 32-bit primitive");
ASSERT(sizeof(long long) == 8, "Replace long long with 64-bit primitive");
ASSERT(sizeof(float) == 4, "Replace float with 32-bit primitive");
ASSERT(sizeof(double) == 8, "Replace double with 64-bit primitive");
ASSERT(sizeof(long double) == 12, "Replace long double with 96-bit primitive");
That way if I port my code to a platform or compiler that has a difference, I can do a quick bulk replace of the primitive that doesn't match up to what I expect
I have a huge header file full of those things for large projects, especially since I use cross-platform libraries that may be built differently, specifically wxWidgets.
It can also be nice to have your own number classes, and if implemented with SIMD and memory aligned they can be much faster than the built in types. Then you know exactly what they are doing, and know exactly how they will round off without worrying what order you declared them, or have very large values etc.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|