Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. long data type with 64-bit

long data type with 64-bit

Scheduled Pinned Locked Moved C / C++ / MFC
question
10 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Alexander M
    wrote on last edited by
    #1

    Hello everyone, I have a question concerning the long data type. Using a 32-bit compiler, sizeof(long) = 4. But what about 64-bit? Regards, Alex Don't try it, just do it! ;-)

    Z T N 3 Replies Last reply
    0
    • A Alexander M

      Hello everyone, I have a question concerning the long data type. Using a 32-bit compiler, sizeof(long) = 4. But what about 64-bit? Regards, Alex Don't try it, just do it! ;-)

      Z Offline
      Z Offline
      Zac Howland
      wrote on last edited by
      #2

      long is still 32-bits in a 64-bit compiler. If you want to have a 64-bit integer, use long long (platform independent) or __int64 (Windows). If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

      1 Reply Last reply
      0
      • A Alexander M

        Hello everyone, I have a question concerning the long data type. Using a 32-bit compiler, sizeof(long) = 4. But what about 64-bit? Regards, Alex Don't try it, just do it! ;-)

        T Offline
        T Offline
        toxcct
        wrote on last edited by
        #3

        short int is the same as short long int is the same as long sizeof(short) returns 2 sizeof(long) returns 4 on a 16 bits environment : sizeof(int) returns 2 on a 32 bits environment : sizeof(int) returns 4 on a 64 bits environment : sizeof(int) returns 8 sizeof(long long) is supposed to return 8, but it is not provided by the standard, and not every compilers know that type. sizeof(__int64) is quite the same as long long, but AFAIK, it is a microsoft specific type, so, not portable either...


        TOXCCT >>> GEII power

        [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

        Z 1 Reply Last reply
        0
        • T toxcct

          short int is the same as short long int is the same as long sizeof(short) returns 2 sizeof(long) returns 4 on a 16 bits environment : sizeof(int) returns 2 on a 32 bits environment : sizeof(int) returns 4 on a 64 bits environment : sizeof(int) returns 8 sizeof(long long) is supposed to return 8, but it is not provided by the standard, and not every compilers know that type. sizeof(__int64) is quite the same as long long, but AFAIK, it is a microsoft specific type, so, not portable either...


          TOXCCT >>> GEII power

          [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

          Z Offline
          Z Offline
          Zac Howland
          wrote on last edited by
          #4

          toxcct wrote:

          on a 64 bits environment : sizeof(int) returns 8

          This is not currently the case, and many on the standards committee are arguing against making it so for backwards compatibility reasons. Currently, on 64-bit compilers, sizeof(int) will return 4 (just like on 32-bit compilers). sizeof(long long), which most compilers support and is being discussed as part of the next standard, will return 8. sizeof(void*) will return 8 on a 64-bit compiler. Note that much of that is still subject to change ... we should know for sure when/if the standard's committee is able to agree on things by 2008. As a side note, it is best to declare the type of integer you actually want (or typedef it) instead of declaring "int" for precisely this reason. If you need low numbers (less than 255/127), use unsigned char/char; if you need larger numbers, use unsigned short/short; and if you need huge numbers, use unsigned long/long. Finally, on 64-bit systems, if you really need the massive numbers, use unsigned long long/long long. It will help save you some portability issues down the road. If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac -- modified at 13:30 Thursday 22nd June, 2006

          J A 2 Replies Last reply
          0
          • A Alexander M

            Hello everyone, I have a question concerning the long data type. Using a 32-bit compiler, sizeof(long) = 4. But what about 64-bit? Regards, Alex Don't try it, just do it! ;-)

            N Offline
            N Offline
            Nemanja Trifunovic
            wrote on last edited by
            #5

            Alexander M. wrote:

            Using a 32-bit compiler, sizeof(long) = 4. But what about 64-bit?

            On Windows, still 4. On most Unix-like systems: 8 In general: implementation dependent.


            My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.

            1 Reply Last reply
            0
            • Z Zac Howland

              toxcct wrote:

              on a 64 bits environment : sizeof(int) returns 8

              This is not currently the case, and many on the standards committee are arguing against making it so for backwards compatibility reasons. Currently, on 64-bit compilers, sizeof(int) will return 4 (just like on 32-bit compilers). sizeof(long long), which most compilers support and is being discussed as part of the next standard, will return 8. sizeof(void*) will return 8 on a 64-bit compiler. Note that much of that is still subject to change ... we should know for sure when/if the standard's committee is able to agree on things by 2008. As a side note, it is best to declare the type of integer you actually want (or typedef it) instead of declaring "int" for precisely this reason. If you need low numbers (less than 255/127), use unsigned char/char; if you need larger numbers, use unsigned short/short; and if you need huge numbers, use unsigned long/long. Finally, on 64-bit systems, if you really need the massive numbers, use unsigned long long/long long. It will help save you some portability issues down the road. If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac -- modified at 13:30 Thursday 22nd June, 2006

              J Offline
              J Offline
              Jorgen Sigvardsson
              wrote on last edited by
              #6

              Zac Howland wrote:

              use unsigned long long/long long. It will help save you some portability issues down the road.

              I'd recommend using typedefs and __int64. That's far easier to maintain, should long long mean anything else than 64 bits on a specific platform/compiler. My 2 cents. :)

              -- 100% natural. No superstitious additives.

              Z 1 Reply Last reply
              0
              • Z Zac Howland

                toxcct wrote:

                on a 64 bits environment : sizeof(int) returns 8

                This is not currently the case, and many on the standards committee are arguing against making it so for backwards compatibility reasons. Currently, on 64-bit compilers, sizeof(int) will return 4 (just like on 32-bit compilers). sizeof(long long), which most compilers support and is being discussed as part of the next standard, will return 8. sizeof(void*) will return 8 on a 64-bit compiler. Note that much of that is still subject to change ... we should know for sure when/if the standard's committee is able to agree on things by 2008. As a side note, it is best to declare the type of integer you actually want (or typedef it) instead of declaring "int" for precisely this reason. If you need low numbers (less than 255/127), use unsigned char/char; if you need larger numbers, use unsigned short/short; and if you need huge numbers, use unsigned long/long. Finally, on 64-bit systems, if you really need the massive numbers, use unsigned long long/long long. It will help save you some portability issues down the road. If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac -- modified at 13:30 Thursday 22nd June, 2006

                A Offline
                A Offline
                Alexander M
                wrote on last edited by
                #7

                That standard is so stupid... they should use long as synonym for char *, which makes pointer arithmetic easier. At the moment there is a big problem when you want to cast a pointer to an integer, especially if you are creating source code for different platforms and compilers. Windows defines ULONG_PTR etc, but I've never heard of a Linux equivalent :(. VC++ and GCC are also very different in some cases, that's getting on my nerves... Thanks for your answers! Don't try it, just do it! ;-)

                Z 1 Reply Last reply
                0
                • J Jorgen Sigvardsson

                  Zac Howland wrote:

                  use unsigned long long/long long. It will help save you some portability issues down the road.

                  I'd recommend using typedefs and __int64. That's far easier to maintain, should long long mean anything else than 64 bits on a specific platform/compiler. My 2 cents. :)

                  -- 100% natural. No superstitious additives.

                  Z Offline
                  Z Offline
                  Zac Howland
                  wrote on last edited by
                  #8

                  I agree with the typedefs, but __int64 only means something for Microsoft's compiler. If you use any other compiler, it is meaningless (or you would have to typedef it to long long). If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

                  J 1 Reply Last reply
                  0
                  • A Alexander M

                    That standard is so stupid... they should use long as synonym for char *, which makes pointer arithmetic easier. At the moment there is a big problem when you want to cast a pointer to an integer, especially if you are creating source code for different platforms and compilers. Windows defines ULONG_PTR etc, but I've never heard of a Linux equivalent :(. VC++ and GCC are also very different in some cases, that's getting on my nerves... Thanks for your answers! Don't try it, just do it! ;-)

                    Z Offline
                    Z Offline
                    Zac Howland
                    wrote on last edited by
                    #9

                    That assumption is why we have the problems with int, long, and void* today. In the 32-bit standard, they were all the same size, so programmers would take advantage of that and cast 32-bit pointers to integers. The problem is now that when you want to run a 32-bit application on a 64-bit platform, that assumption breaks your code (not desirable). To prevent this from happening, one of the proposals being discussed is to create a long long datatype for 64 bits, long and int would still be 32 bits, short would still be 16 bits, and char woudl still be 8 bits. void* would be 64 bits. As for the ULONG_PTR and INT_PTR ... those are just typedefs (use to be #define's). They are handy for recompiling in 64 bit mode, but still run into the same problems when you try to run a 32 bit application on a 64 bit platform. The presense or absense of those definitions has nothing to do with the actual compiler and everything to do with the utility libraries. You can VERY easily create your own. If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

                    1 Reply Last reply
                    0
                    • Z Zac Howland

                      I agree with the typedefs, but __int64 only means something for Microsoft's compiler. If you use any other compiler, it is meaningless (or you would have to typedef it to long long). If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

                      J Offline
                      J Offline
                      Jorgen Sigvardsson
                      wrote on last edited by
                      #10

                      I see that I didn't really express what I meant. I really meant that the typedef should be changed to alias to the platform specific 64 bit type. (And not just the microsoft __int64 type)

                      -- 100% natural. No superstitious additives.

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups