Re: TMath::Sort :: warning if n < array size

From: Axel Naumann <Axel.Naumann_at_cern.ch>
Date: Sun, 21 Aug 2011 22:56:04 +0200


Hi,

On 8/21/11 4:43 PM, Adrian Sevcenco wrote:

> On 08/21/11 16:58, Axel Naumann wrote:

>> Thanks for your suggestion. We can't determine the sizeof(index), all we
>> have is a pointer (not an array), and that would just return you
>> sizeof(void*).

> hmm .. that would mean that the arrays that are the arguments are > deprecated somewhere somehow to (void*)

Deprecated? I don't understand that. Maybe you're referring to the array-to-pointer decay? Yes, that's the case when calling Sort() passing an array in.

Sort() only sees the starting address of the arrays (const Element*, Index*), it doesn't know their size which needs to be provided through the argument "n".

Cheers, Axel.

>> A recommendation: you could have used valgrind to find this problem in
>> your usage of Sort().

> well, this is how i found out my problem in my code (i did some copy
> paste of an sort and i forgot to adjust the number of elements..)
> 
> Thanks,
> Adrian
> 

>>
>> Cheers, Axel.
>>
>>
>> On 8/21/11 1:29 AM, Adrian Sevcenco wrote:
>>> Hi! I was wondering if would be useful (for me it would because i just
>>> had some headaches because of this) to have a warning in case that
>>> either (this arguments related to [1]):
>>> 1. n < sizeof(index)/sizeof(index[0])
>>> or
>>> 2. sizeof(index) < sizeof(a)
>>>
>>> and definitely an error (if it is needed..) for
>>> n > sizeof(a)
>>>
>>> Thanks,
>>> Adrian
>>>
>>> [1]. http://root.cern.ch/root/html/src/TMath.h.html#YYNCbB
>>
Received on Sun Aug 21 2011 - 22:56:11 CEST

This archive was generated by hypermail 2.2.0 : Mon Aug 22 2011 - 05:50:01 CEST