www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/07/26/12:05:15

Date: Thu, 26 Jul 2001 19:04:30 +0300 (IDT)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: Tim Van Holder <tim DOT vanholder AT falconsoft DOT be>
cc: Martin Str|mberg <ams AT father DOT ludd DOT luth DOT se>, djgpp AT delorie DOT com,
kos AT kbtem DOT by
Subject: Re: Why so?
In-Reply-To: <3B602371.86D2F40E@falconsoft.be>
Message-ID: <Pine.SUN.3.91.1010726185920.2777C-100000@is>
MIME-Version: 1.0
Reply-To: djgpp AT delorie DOT com
Errors-To: nobody AT delorie DOT com
X-Mailing-List: djgpp AT delorie DOT com
X-Unsubscribes-To: listserv AT delorie DOT com
Thread: Frames, NoFrames, TwoWindows

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 -


  webmaster   donations   bookstore     delorie software   privacy  
  Copyright 2014   by DJ Delorie     Updated Aug 2014