Mail Archives: djgpp/2001/07/26/12:05:15
On Thu, 26 Jul 2001, Tim Van Holder wrote:
> > : Other compilers give me:
> > : 01234
> > : 01234
> > : 01234567
> > : 01234567
> >
> > Only (bad) luck.
>
> Actually, no - it IS odd.
``Odd'' is what undefined behavior is all about ;-)
> With the code he posted, if the strcat does
> not cause a segmentation fault, you'd expect the output he posted as
> resulting from other compilers; the relevant snippet is:
>
> > : puts(str);
> > : printf("%s\n",str);
>
> Regardless of what str points to, neither of these modify str in any
> way, so both should print the same value.
You are assuming that the cursor was positioned at the left edge of the
screen before each one of these two statements. Given the unknown
contents of the string, that might or might not be the case, because we
have no idea where did the call to `puts' leave the cursor. It is quite
possible that the second statement overwrote parts of the string printed
by the first, for example.
- Raw text -