digitalmars.D.bugs - index overflow
- Bent Rasmussen (11/12) Jul 31 2004 struct vector (T, uint N)
- h3r3tic (14/37) Jul 31 2004 I dont't think it's a bug except for the signed output. What happens
- Bent Rasmussen (1/1) Jul 31 2004 You're right, I was too quick on that one.
struct vector (T, uint N) { T[N] S; .vector!(T,N*2) opCat(vector a); } alias vector!(float,3) float3; void main() { }dmd.exe test.dtest.d(5): index -1073741824 overflow for static array XP DMD 0.97
Jul 31 2004
Bent Rasmussen wrote:struct vector (T, uint N) { T[N] S; .vector!(T,N*2) opCat(vector a); } alias vector!(float,3) float3; void main() { }I dont't think it's a bug except for the signed output. What happens here is that vector is instantiated recursively by having N = 3, then 3*2, 3*4, 3*8, 3*16, 3*32, ... until it reaches 3*2^30. It's equal 3221225472 then. 3*2^30 when stored in a signed int == -1073741824. If that 3*2^30 were to be multiplied by 2 once more, it would overflow the dword storage it's given and be equal 6*2^30 == 3*2^31 and thats more than 2^32-1 which cannot be handled by a dword. Here, the compiler properly signals that something is wrong. It could give some more meaningful information though, at least by printing the number as an unsigned int. I'm not sure but I think it's a downside of the en-masse template instantiation we have in D. havent tried this kind of thing in C++ though... regards, Tomdmd.exe test.dtest.d(5): index -1073741824 overflow for static array XP DMD 0.97
Jul 31 2004
You're right, I was too quick on that one.
Jul 31 2004