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. Size of datatype dependent on OS or Hardware Architecture?

Size of datatype dependent on OS or Hardware Architecture?

Scheduled Pinned Locked Moved C / C++ / MFC
c++hardwarearchitecturequestion
4 Posts 4 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.
  • Q Offline
    Q Offline
    QuickDeveloper
    wrote on last edited by
    #1

    hi i would like to know if whether the size of datatype C++ is dependant on which of the following ( or on all of them ) ? 1)Operating System 2)Hardware Architecture 3)Compiler Eg:Does size of int on 64 bit Hardware with 32/64 bit windows varies?

    "Every morning I go through Forbes list of 40 richest people in the world. If my name is not in there, I go to work..!!!"

    D I S 3 Replies Last reply
    0
    • Q QuickDeveloper

      hi i would like to know if whether the size of datatype C++ is dependant on which of the following ( or on all of them ) ? 1)Operating System 2)Hardware Architecture 3)Compiler Eg:Does size of int on 64 bit Hardware with 32/64 bit windows varies?

      "Every morning I go through Forbes list of 40 richest people in the world. If my name is not in there, I go to work..!!!"

      D Offline
      D Offline
      Divyang Mithaiwala
      wrote on last edited by
      #2

      size of int is depend on Compiler. Compiler is depend on Operating System. Operating System is depend on Hardware Architecture.


      Do not trust a computer... Always check what computer is doing regards, Divyang Mithaiwala Software Engineer

      1 Reply Last reply
      0
      • Q QuickDeveloper

        hi i would like to know if whether the size of datatype C++ is dependant on which of the following ( or on all of them ) ? 1)Operating System 2)Hardware Architecture 3)Compiler Eg:Does size of int on 64 bit Hardware with 32/64 bit windows varies?

        "Every morning I go through Forbes list of 40 richest people in the world. If my name is not in there, I go to work..!!!"

        I Offline
        I Offline
        Iain Clarke Warrior Programmer
        wrote on last edited by
        #3

        According to the C spec, int is a convenient size for that system. char, short and long are always the same size. Not so sure about float and double... As for structures, they can also vary, due to structure padding. That should give you enough google material / questions to ask your teacher. Iain.

        In the process of moving to Sweden for love (awwww). If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), give me a job! http://cv.imcsoft.co.uk/[^]

        1 Reply Last reply
        0
        • Q QuickDeveloper

          hi i would like to know if whether the size of datatype C++ is dependant on which of the following ( or on all of them ) ? 1)Operating System 2)Hardware Architecture 3)Compiler Eg:Does size of int on 64 bit Hardware with 32/64 bit windows varies?

          "Every morning I go through Forbes list of 40 richest people in the world. If my name is not in there, I go to work..!!!"

          S Offline
          S Offline
          Stuart Dootson
          wrote on last edited by
          #4

          QuickDeveloper wrote:

          size of datatype C++ is dependant on which of the following ( or on all of them ) ? 1)Operating System 2)Hardware Architecture 3)Compiler

          The data-type size is primarily specified by the compiler. The size used by the compiler will be chosen to make implementation of the data-type easy. So, on a 16-bit processor, ints are likely to be 16-bit, while on a 32-bit compiler, they're likely to be 32-bit. When you get to 64-bit hardware, you have more choices. 32- or 64-bit ints are natively supported, but you'll probably find they choose 32-bit integers because a) that is in general big enough for most applications, and b) 32-bit ints are half the size of 64-bit ints - moving all ints to 64-bit would probably cause space and speed (because you have to read twice as much memory for ints) issues. You still, of course have access to 64-bit ints through __int64 and long long.

          QuickDeveloper wrote:

          Eg:Does size of int on 64 bit Hardware with 32/64 bit windows varies?

          I don't believe so. IIRC, the 64-bit Windows API uses 32-bit integer values and 64-bit pointer values, compared to 32-bit Windows, which uses 32-bit integers and 32-bit pointers. [bit later] I've just checked (by compiling with the x86->amd64 cross-compiling version of VC++ and looking at the generated assembler) and VC++ does indeed use 32-bit integers for x86 AND x64.

          Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

          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