Path: utzoo!mnetor!uunet!lll-winken!lll-tis!ames!ll-xn!mit-eddie!uw-beaver!ssc-vax!cxsea!blm From: blm@cxsea.UUCP (Brian Matthews) Newsgroups: comp.lang.c Subject: Re: Useful macro...or dangerous?? Message-ID: <2397@cxsea.UUCP> Date: 2 May 88 15:38:20 GMT References: <221@raunvis.UUCP> <11255@mimsy.UUCP> Reply-To: blm@cxsea.UUCP (Brian Matthews) Organization: Computer X Inc. Lines: 46 Chris Torek (chris@mimsy.UUCP) writes: |[Dangerous] |In article <221@raunvis.UUCP> kjartan@raunvis.UUCP (Kjartan Pier |Emilsson Jardedlisfraedi) writes: |For instance, if I write | | struct holey { | char ch; | int i; | } smokes, batman; | |there is often a `gap' between `ch' and `i'. Another problem that may occur is if you have something like: struct maybe_holey { char arr[16]; } string, array; then do something like: strcpy (string.arr, "kiwi fruit"); strcpy (string.arr, "bananas"); ... strcpy (array,arr, "mangos"); strcpy (string.arr, "mangos"); equal will now report that array and string aren't equal, even though they should be considered equal. The reason is of course that the characters beyond the end of the string aren't significant in this case, but equal doesn't know this. This is one of the reasons that structure equality can't be done reasonably in the compiler. In general, the compiler will know about the gaps that Chris mentions, but it won't know whether string.arr is being used as an array, where all characters are significant, or a string, where only the characters up to and including the null are significant. And of course equal can't know either of these. |In short, it is safest not to do this. Agreed. -- Brian L. Matthews "The first time I died, ...{mnetor,uw-beaver!ssc-vax}!cxsea!blm was in the arms of good +1 206 251 6811 friends of mine." Computer X Inc. - a division of Motorola New Enterprises