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. why CArray::GetSize() returns INT_PTR

why CArray::GetSize() returns INT_PTR

Scheduled Pinned Locked Moved C / C++ / MFC
data-structures
9 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.
  • R Offline
    R Offline
    Raj Prathap
    wrote on last edited by
    #1

    Hi All, Please explain me why CArray::GetSize() returns an INT_PTR. When I see the documentation regarding the function, it says returns the number of elements in the array. Number of elements are int/long. I could not understand why is this INT_PTR. In VS2k3, the compiler throws a warning. In VC6.0 there is no warning. Regards, Pratap

    N J T 3 Replies Last reply
    0
    • R Raj Prathap

      Hi All, Please explain me why CArray::GetSize() returns an INT_PTR. When I see the documentation regarding the function, it says returns the number of elements in the array. Number of elements are int/long. I could not understand why is this INT_PTR. In VS2k3, the compiler throws a warning. In VC6.0 there is no warning. Regards, Pratap

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

      Raj Prathap wrote:

      Number of elements are int/long.

      What do you mean by that? As far as I can see, all functions that deal with the number of elements or indices are INT_PTR. The reason for that is 64-bit compatibility.


      Programming Blog utf8-cpp

      1 Reply Last reply
      0
      • R Raj Prathap

        Hi All, Please explain me why CArray::GetSize() returns an INT_PTR. When I see the documentation regarding the function, it says returns the number of elements in the array. Number of elements are int/long. I could not understand why is this INT_PTR. In VS2k3, the compiler throws a warning. In VC6.0 there is no warning. Regards, Pratap

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

        int is defined to be 32bit (not in the standard, but by common use) CArray can theoretically hold more than 4Gig Items, at least in 64 bit Windows. That would need a 64 bit integer. Here the INT_PTR kicks in: It defines a signed (there's also UINT_PTR) integer datatype that has at least the size to hold a pointer in the specific architecture. So, in 64 bit Windows, it would be a 64 bit integer.

        Raj Prathap wrote:

        Number of elements are int/long.

        Actually, I would expect the count of elements in a collection to be a unsigned value. I can't imagine a use for a negative count.


        Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
        George Orwell, "Keep the Aspidistra Flying", Opening words

        J 1 Reply Last reply
        0
        • R Raj Prathap

          Hi All, Please explain me why CArray::GetSize() returns an INT_PTR. When I see the documentation regarding the function, it says returns the number of elements in the array. Number of elements are int/long. I could not understand why is this INT_PTR. In VS2k3, the compiler throws a warning. In VC6.0 there is no warning. Regards, Pratap

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

          INT_PTR is NOT a pointer, it is an integer ! the _PTR at the end just means that this type is as large as a pointer type (32 bits on a 32 bits machine, 64 on a x64...)


          [VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]

          1 Reply Last reply
          0
          • J jhwurmbach

            int is defined to be 32bit (not in the standard, but by common use) CArray can theoretically hold more than 4Gig Items, at least in 64 bit Windows. That would need a 64 bit integer. Here the INT_PTR kicks in: It defines a signed (there's also UINT_PTR) integer datatype that has at least the size to hold a pointer in the specific architecture. So, in 64 bit Windows, it would be a 64 bit integer.

            Raj Prathap wrote:

            Number of elements are int/long.

            Actually, I would expect the count of elements in a collection to be a unsigned value. I can't imagine a use for a negative count.


            Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
            George Orwell, "Keep the Aspidistra Flying", Opening words

            J Offline
            J Offline
            James R Twine
            wrote on last edited by
            #5

            jhwurmbach wrote:

            Actually, I would expect the count of elements in a collection to be a unsigned value. I can't imagine a use for a negative count.

            Error return, at least in a poorly designed implementation... For example, you call a function called PopulateCollection(...), passing in the collection object and it returns an int value:

            n  > 0 -- collection now contains n elements
                 n == 0 -- collection now contains no elements
                 n  < 0 -- error manipulating collection

            Peace!

            -=- James
            Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
            Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
            See DeleteFXPFiles

            J 1 Reply Last reply
            0
            • J James R Twine

              jhwurmbach wrote:

              Actually, I would expect the count of elements in a collection to be a unsigned value. I can't imagine a use for a negative count.

              Error return, at least in a poorly designed implementation... For example, you call a function called PopulateCollection(...), passing in the collection object and it returns an int value:

              n  > 0 -- collection now contains n elements
                   n == 0 -- collection now contains no elements
                   n  < 0 -- error manipulating collection

              Peace!

              -=- James
              Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
              Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
              See DeleteFXPFiles

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

              Very poor implementation. It would be mixing two concepts into one return value. When manipulations are incorect, these manipulation-functions have to report faliure. In your example, the number of elements returned is only an additional gimmick, not the purpose of the function. Asking for the number of elements can only return a number. There is no possible error case.


              Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
              George Orwell, "Keep the Aspidistra Flying", Opening words

              J 1 Reply Last reply
              0
              • J jhwurmbach

                Very poor implementation. It would be mixing two concepts into one return value. When manipulations are incorect, these manipulation-functions have to report faliure. In your example, the number of elements returned is only an additional gimmick, not the purpose of the function. Asking for the number of elements can only return a number. There is no possible error case.


                Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
                George Orwell, "Keep the Aspidistra Flying", Opening words

                J Offline
                J Offline
                James R Twine
                wrote on last edited by
                #7

                As I said, a poor implementaiton1 :)

                jhwurmbach wrote:

                Asking for the number of elements can only return a number. There is no possible error case.

                That actually depends on how the collection is being accessed.  For example, suppose you have an object that warps a simple array.  The object could be in a state where it is not yet associated with, or has been detached from, an array.  Asking the object for the number of elements should return... What?    Returning zero means that the collection has a size of zero, not that there is no collection.  Again, a poor implementation, but just because you cannot think of a good reason for doing something does not mean that others cannot think of many bad reasons for doing it! :)    Peace!

                -=- James
                Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
                Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
                See DeleteFXPFiles

                J 1 Reply Last reply
                0
                • J James R Twine

                  As I said, a poor implementaiton1 :)

                  jhwurmbach wrote:

                  Asking for the number of elements can only return a number. There is no possible error case.

                  That actually depends on how the collection is being accessed.  For example, suppose you have an object that warps a simple array.  The object could be in a state where it is not yet associated with, or has been detached from, an array.  Asking the object for the number of elements should return... What?    Returning zero means that the collection has a size of zero, not that there is no collection.  Again, a poor implementation, but just because you cannot think of a good reason for doing something does not mean that others cannot think of many bad reasons for doing it! :)    Peace!

                  -=- James
                  Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
                  Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
                  See DeleteFXPFiles

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

                  James R. Twine wrote:

                  The object could be in a state where it is not yet associated with, or has been detached from, an array. Asking the object for the number of elements should return... What?

                  0. No elements would be retrievable.

                  James R. Twine wrote:

                  Returning zero means that the collection has a size of zero, not that there is no collection.

                  Why sould the "GetSize"-function answer a question other than that "How many elements are in the collection?". There are no elements to be retrieved, so the answer is null. If your collection happens to have a state of being "invalid", there sould be another function to test that. Note that I would have the actual access-routines return a proper error code.


                  Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
                  George Orwell, "Keep the Aspidistra Flying", Opening words

                  J 1 Reply Last reply
                  0
                  • J jhwurmbach

                    James R. Twine wrote:

                    The object could be in a state where it is not yet associated with, or has been detached from, an array. Asking the object for the number of elements should return... What?

                    0. No elements would be retrievable.

                    James R. Twine wrote:

                    Returning zero means that the collection has a size of zero, not that there is no collection.

                    Why sould the "GetSize"-function answer a question other than that "How many elements are in the collection?". There are no elements to be retrieved, so the answer is null. If your collection happens to have a state of being "invalid", there sould be another function to test that. Note that I would have the actual access-routines return a proper error code.


                    Though I speak with the tongues of men and of angels, and have not money, I am become as a sounding brass, or a tinkling cymbal.
                    George Orwell, "Keep the Aspidistra Flying", Opening words

                    J Offline
                    J Offline
                    James R Twine
                    wrote on last edited by
                    #9

                    jhwurmbach wrote:

                    0. No elements would be retrievable. Why sould the "GetSize"-function answer a question other than that "How many elements are in the collection?". There are no elements to be retrieved, so the answer is [zero].

                    The number of elements that are in a collection is not the same as the number of elements that are retrievable/available.  GetSize() vs. GetAvailable().  The lot at the Aston Martin dealership contain 87 cars, but zero of them are available to me! :laugh:    This is becoming a pointless argument :) - you will recall in my OP that I mention the words "poor design".  And I have seen lots of poor designs and heard many ways of defending/rationalizing them.    Peace!

                    -=- James
                    Please rate this message - let me know if I helped or not! * * * If you think it costs a lot to do it right, just wait until you find out how much it costs to do it wrong!
                    Avoid driving a vehicle taller than you and remember that Professional Driver on Closed Course does not mean your Dumb Ass on a Public Road!
                    See DeleteFXPFiles

                    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