Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript |
c++ - undetected negative or zero size.
Hi, The compiler compiled the following code. int main() { int array1[0]; int array2[-1]; return 0; } I believe the compiler should issue the errors instead. Jun 07 2001
<g> I can not believe people actually try this!!! When you buy a car do you also run it into the crash barrier to see how it looks after wards?? <g> Suradet Jitprapaikulsarn wrote:Hi, The compiler compiled the following code. int main() { int array1[0]; int array2[-1]; return 0; } I believe the compiler should issue the errors instead. Jun 07 2001
In article <3B204AFD.6B5CCD75 smartsoft.cc>, Jan Knepper (jan smartsoft.cc) says...<g> I can not believe people actually try this!!! When you buy a car do you also run it into the crash barrier to see how it looks after wards?? <g> Jun 27 2002
Agreed. Compile-time asserts are extremely useful, and cost nothing. They should be facilitated by [-ve] errors as a priority "Larry Brasfield" <larry_brasfield snotmail.com> wrote in message news:MPG.1784fe26d69af93a989680 news.digitalmars.com...In article <3B204AFD.6B5CCD75 smartsoft.cc>, Jan Knepper (jan smartsoft.cc) says...<g> I can not believe people actually try this!!! When you buy a car do you also run it into the crash barrier to see how it looks after wards?? <g> Jun 27 2002
Sure! #include <stdio.h> int main ( int, char **, char ** ) { int a [ 128 ]; int *b = ( a + 64 ); for ( int i = 0 ; i < 128 ; i++ ) a [ i ] = i - 64; // ... for ( i = -64 ; i < 64 ; i++ ) printf ( "%3d ", b [ i ] ); } Larry Brasfield wrote:In article <3B204AFD.6B5CCD75 smartsoft.cc>, Jan Knepper (jan smartsoft.cc) says...<g> I can not believe people actually try this!!! When you buy a car do you also run it into the crash barrier to see how it looks after wards?? <g> Jun 27 2002
Sorry for being a bit thick, Jan, but I don't get the point you are making with this code. You haven't put a -ve literal into an array declaration, as in int ar[-12]; so it is no surprise that this works. Maybe you are meaning to illustrate something completely different. ???? "Jan Knepper" <jan smartsoft.cc> wrote in message news:3D1BB23F.CBEE2452 smartsoft.cc...Sure! #include <stdio.h> int main ( int, char **, char ** ) { int a [ 128 ]; int *b = ( a + 64 ); for ( int i = 0 ; i < 128 ; i++ ) a [ i ] = i - 64; // ... for ( i = -64 ; i < 64 ; i++ ) printf ( "%3d ", b [ i ] ); } Larry Brasfield wrote:In article <3B204AFD.6B5CCD75 smartsoft.cc>, Jan Knepper (jan smartsoft.cc) says...<g> I can not believe people actually try this!!! When you buy a car do you also run it into the crash barrier to see how it looks after wards?? <g> Jun 27 2002
-1 is 0xffffffff so array[-1] is a valid BIG array Roland Suradet Jitprapaikulsarn a écrit :Hi, The compiler compiled the following code. int main() { int array1[0]; int array2[-1]; return 0; } I believe the compiler should issue the errors instead. Jun 08 2001
Version 8.16 does issue error for the negative sized array. Not very descriptive (internal error cgcod 585) but the error message is there nevertheless. Btw by the language definition there is no bounds checking on arrays in C, so do not expect one, unless there is a code/data overflow. In a 32 bit world, an array of 1073741828 integers takes up exactly 16 bytes because of modulo 2^32 arithmetic (I will let you figure that one out). Suradet Jitprapaikulsarn wrote:Hi, The compiler compiled the following code. int main() { int array1[0]; int array2[-1]; return 0; } I believe the compiler should issue the errors instead. Jun 08 2001
Suradet Jitprapaikulsarn a écrit :Hi, The compiler compiled the following code. int main() { int array1[0]; int array2[-1]; return 0; } I believe the compiler should issue the errors instead. Jun 28 2002
|