TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: Neil Heller
from: Jasen Betts
date: 2004-04-20 18:06:50
subject: Squares

Hi Neil.

17-Apr-04 20:33:00, Neil Heller wrote to Darin McBride


 JB>>>>> and possibly even better re-written to use a char* instead

 JB>>>>> for( s=target ; *s ; s++ ) {...};


 BB>>> char *s=target; while(*s++) {...};

 BB>>> simpler, neater, more direct.

 JB>> but not equivalent.

 NH> DM>Good catch!

 NH> How so?  These sure _look_ like they do the same thing.

In the while version the first time through the block s==target+1
in the for version loop s==target. etc...

 JB>> char *s=target-1; while(*++s) {...};

 NH> DM>Not supported by the standard ;-)

 NH> what happens when you point to memory that is not given to you
 NH> by the compiler

Undefined behavior apparently.  according to the rules
anything _could_ happen,

 -=> Bye <=-

---
* Origin: Keyboard not connected, press to continue. (3:640/1042)
SEEN-BY: 633/267 270
@PATH: 640/1042 531 954 774/605 123/500 106/2000 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.