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. Regarding Problem with Short Data Type

Regarding Problem with Short Data Type

Scheduled Pinned Locked Moved C / C++ / MFC
c++performancehelpquestion
7 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.
  • P Offline
    P Offline
    paresh_joe
    wrote on last edited by
    #1

    in some c++ coding standard guidance i noticed following text written : "Avoid using short as its still generally packaged into a 32 bit chunk of memory. There are very few places where a short can be justified over a long." Can someone explain why is it so ?

    CPalliniC S 2 Replies Last reply
    0
    • P paresh_joe

      in some c++ coding standard guidance i noticed following text written : "Avoid using short as its still generally packaged into a 32 bit chunk of memory. There are very few places where a short can be justified over a long." Can someone explain why is it so ?

      CPalliniC Offline
      CPalliniC Offline
      CPallini
      wrote on last edited by
      #2

      That is don't use UNICODE strings?. :rolleyes: BTW probably you should give some more info about the context of the above statement. Sometimes taking a sentence out of its context doesn't make sense. :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke

      In testa che avete, signor di Ceprano?

      1 Reply Last reply
      0
      • P paresh_joe

        in some c++ coding standard guidance i noticed following text written : "Avoid using short as its still generally packaged into a 32 bit chunk of memory. There are very few places where a short can be justified over a long." Can someone explain why is it so ?

        S Offline
        S Offline
        Saurabh Garg
        wrote on last edited by
        #3

        Well it seems that author is trying to say that since a short which is 16 bit long is internally stored as 32 bit number it doesn't make sense to use it. I am not sure if this indeed is the case. -Saurabh

        J 1 Reply Last reply
        0
        • S Saurabh Garg

          Well it seems that author is trying to say that since a short which is 16 bit long is internally stored as 32 bit number it doesn't make sense to use it. I am not sure if this indeed is the case. -Saurabh

          J Offline
          J Offline
          jhwurmbach
          wrote on last edited by
          #4

          Saurabh.Garg wrote:

          I am not sure if this indeed is the case.

          It depends on the compiler and platform. "1==sizeof(char)<=sizeof(short)<=sizeof(int)<=sizeof(long)<=sizeof(long long)" is all the standard says. This tends to be interpreted as "char is 8 bits, short is 16 bits, int is 32 bits and long is 64 bits". But it doesn't need to be that case.

          Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all.
          Douglas Adams, "Dirk Gently's Holistic Detective Agency"

          S 1 Reply Last reply
          0
          • J jhwurmbach

            Saurabh.Garg wrote:

            I am not sure if this indeed is the case.

            It depends on the compiler and platform. "1==sizeof(char)<=sizeof(short)<=sizeof(int)<=sizeof(long)<=sizeof(long long)" is all the standard says. This tends to be interpreted as "char is 8 bits, short is 16 bits, int is 32 bits and long is 64 bits". But it doesn't need to be that case.

            Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all.
            Douglas Adams, "Dirk Gently's Holistic Detective Agency"

            S Offline
            S Offline
            Saurabh Garg
            wrote on last edited by
            #5

            Yes you are right but if you read original question again it says: "Avoid using short as its still generally packaged into a 32 bit chunk of memory. There are very few places where a short can be justified over a long." It clearly indicates that author is implying that short is not 32-bit but is generally packages as 32-bit. So I was just trying to say that I am not sure that short is packaged as 32-bit. -Saurabh

            J 1 Reply Last reply
            0
            • S Saurabh Garg

              Yes you are right but if you read original question again it says: "Avoid using short as its still generally packaged into a 32 bit chunk of memory. There are very few places where a short can be justified over a long." It clearly indicates that author is implying that short is not 32-bit but is generally packages as 32-bit. So I was just trying to say that I am not sure that short is packaged as 32-bit. -Saurabh

              J Offline
              J Offline
              jhwurmbach
              wrote on last edited by
              #6

              Saurabh.Garg wrote:

              It clearly indicates that author is implying that short is not 32-bit but is generally packages as 32-bit.

              There is not ehough information available to rule out any of at least two possibilities: - They need to support some (exotic?) platform where short == int == long. - The sentece refers to #pragma pack, which defaults to a 32Bit boundaries to gain a significant speed boost at the expense of a non-significant amount of memory. The last possibility would be that rule is like 99% of all coding standard rules: Utter crap, designed to stop the programmers from doing real work.

              Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all.
              Douglas Adams, "Dirk Gently's Holistic Detective Agency"

              S 1 Reply Last reply
              0
              • J jhwurmbach

                Saurabh.Garg wrote:

                It clearly indicates that author is implying that short is not 32-bit but is generally packages as 32-bit.

                There is not ehough information available to rule out any of at least two possibilities: - They need to support some (exotic?) platform where short == int == long. - The sentece refers to #pragma pack, which defaults to a 32Bit boundaries to gain a significant speed boost at the expense of a non-significant amount of memory. The last possibility would be that rule is like 99% of all coding standard rules: Utter crap, designed to stop the programmers from doing real work.

                Let's think the unthinkable, let's do the undoable, let's prepare to grapple with the ineffable itself, and see if we may not eff it after all.
                Douglas Adams, "Dirk Gently's Holistic Detective Agency"

                S Offline
                S Offline
                Saurabh Garg
                wrote on last edited by
                #7

                Well I don't think author meant any of two things you mentioned.

                jhwurmbach wrote:

                The last possibility would be that rule is like 99% of all coding standard rules: Utter crap, designed to stop the programmers from doing real work.

                I was really trying to say this but I was being polite :-) -Saurabh

                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