|
Boost : |
Subject: Re: [boost] Bug with gcc and array
From: Andreas Klein (klein_at_[hidden])
Date: 2008-11-25 05:45:47
Hello
>
> There is no bug. boost::array does no dynamic memory allocation, so
> you are creating a circa 30 MB array on the stack. This is enough to
> blow the stack size limit on most OSs.
>
>> In contrast a C-array works fine.
>>
>> Since the naturale implementation of the array class is just a wrapper
>> around the C-style array this is very strange.
>
> Sheer luck probably. You have gone beyond an implementation defined
> limit and it is UB. In fact using a C -style array might (or not) have
> blown the stack in the same way.
I guess not. I submitt a minimal example. I found the problem in a big
complicated computaion. With the C array it works fine no crash and gives
the expected result.
> It is not a bug of gcc (although a warning would have been
> appreciated), just a manifestation of UB. It might be that the intel
> compiler sets the stack size limit higher, it disables stack overflow
> checking or simply you are just being lucky (or unlucky, depends on
> how you see it) and UB is not showing up as an hard crash.
>
> Morale: do not stack allocate huge objects.
Do have a reference for me were to find the implementation limits?
Would it a good idea to add a static assert to boost::array that ensures
that the array size is small enough? I think a error message at compile
time is more help full than Segmentation fault at run time.
Best wishes
Andreas Klein
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk