CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 19 of 19
  1. #16
    Join Date
    Jan 2009
    Posts
    1,689

    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.

  2. #17
    Join Date
    Nov 2007
    Location
    Birmingham, England
    Posts
    157

    Re: What is C++ equipvalent of Java Long?

    Quote Originally Posted by monarch_dodra View Post
    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

  3. #18
    Join Date
    Sep 2009
    Posts
    15

    Re: What is C++ equipvalent of Java Long?

    Quote Originally Posted by ictoan View Post
    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

  4. #19

    Re: What is C++ equipvalent of Java Long?

    Quote Originally Posted by ninja9578 View Post
    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.

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured