why CArray::GetSize() returns INT_PTR
-
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
-
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
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.
-
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
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 -
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
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]
-
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 wordsjhwurmbach 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 anint
value:n > 0 -- collection now contains n elements
n == 0 -- collection now contains no elements
n < 0 -- error manipulating collectionPeace!
-=- 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 -
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 anint
value:n > 0 -- collection now contains n elements
n == 0 -- collection now contains no elements
n < 0 -- error manipulating collectionPeace!
-=- 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 DeleteFXPFilesVery 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 -
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 wordsAs 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 -
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 DeleteFXPFilesJames 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 -
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 wordsjhwurmbach 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