Pascal J. Bourguignon wrote:
Pallav singh <singh.pallav@gmail.com> writes:
Hi All ,
the program is not crashing, after 10 iteration of the loop;
int main( )
{
int * ptr = (int *)malloc( 10) ;
while( 1 )
{
printf(" %d \n",*ptr);
ptr++ ;
}
}
Check the other discussion "Books for advanced C++ debugging".
This is formally an "undefined behavior" situation.
We plain programmers would like the implementation to throw an
exception when such a situation occurs.
But it would be more work for compiler writters, so they don't want
to
provide such a feature (much less optionnaly, since that would be
even
more work). And therefore the industry must bear the cost of
uncaught
bugs, of which viruses and worms take benefit.
Personnaly, the only solution I see is to forget C and C++ and
instead
use implementations of different programming languages that provide
such run-time checks and error detection, be it because the
implementers of these other programming languages are not as
stubborn
as C or C++ implementers, or because those other programming
languages
define such an error checking behavior.
Not the only solution. :-)
where it is really needed).
no chance of stepping outside the vector. Safety!