On 08 Mar 2007 08:10:14 -0800, debasish deka <[EMAIL PROTECTED]> wrote:
> I modified your program to :
>
> int main(void)
> {
> char *dst = (char *) malloc(4);
> strcpy(dst, "This is a nice palace");
> puts(dst);
> free(dst);
> puts(dst);
> return 0;
> }
>
> but it isnt showing errors.Only that is showing a single line of output as
> "This is a nice palace"-- thats all.
> I am not finding the reason why ??
Because, as pointed out numerous times before, you're invoking
undefined behaviour. Undefined behaviour can include any of
1) Doing what others might expect by printing something
2) Doing what you expect by crashing
3) Doing what no-one expects by formatting your hard drive.
4) Something else.
Any one, or a combination, of these behaviours are/is acceptable.
Any rationalising as to why a particular behaviour manifests itself on
a particular combination of compiiler, switches and OS is basically
futile.
The reason it's printing something on your system is that you're not
doing 'enough' to do any corruption.
--
PJH
Aio, quantitas magna frumentorum est