Date: Thu, 26 Jul 2001 19:04:30 +0300 (IDT) From: Eli Zaretskii X-Sender: eliz AT is To: Tim Van Holder cc: Martin Str|mberg , djgpp AT delorie DOT com, kos AT kbtem DOT by Subject: Re: Why so? In-Reply-To: <3B602371.86D2F40E@falconsoft.be> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII 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 Precedence: bulk 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.