www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/09/03/03:00:20

From: (SED AT ticnet DOT com)
Newsgroups: comp.os.msdos.djgpp
Subject: Optimizer and logical operators.
Date: Thu, 03 Sep 1998 01:20:37 GMT
Organization: The Internet Connection - ticnet.com (using Airnews.net!)
Lines: 45
Message-ID: <4D580E8D0A378A4D.13E50F10CD0F8074.909D1CC8A7C84CD0@library-proxy.airnews.net>
Abuse-Reports-To: abuse at ticnet.com to report improper postings
NNTP-Proxy-Relay: library3
NNTP-Posting-Time: Wed Sep 2 20:21:25 1998
NNTP-Posting-Host: d-ftH+<VdtBe1BFCh,,>Bl.F%+TMKB (Encoded at Airnews!)
Mime-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

    Hello,
The question I have involves the GNU compilers in general. In the
while loop in the code below, according to my ANSI C book, the 1st
expression of the && operator will be evaluated, then the 2nd
expression will be evaluated if the 1st is true. 

void
str_remove_leading_space( char string[] )
{
    char *p1 = string;

    /* Skip past leading whitespace. */
    while((*p1 != '\0') && isspace( *p1 ))
        ++p1;

   /* Shift remeinder of string backwards to overwrite leading space.
*/
   /* If no leading spaces, then do nothing. */
   if( p1 != string )
       memmove(string, p1, strlen( p1 ) + 1);

   return;
}

So I should be able to rewrite:

while( (*p1 != '\0') && isspace( *p1 ) )
    ++p1;

as

while( (*p1 != '\0') && isspace( *(p1++) ) );

Does the optimizer honor the expression1 && expression2 rule also? In
cases like this would I have to worry about my expressions being
evaluated in a different order if I optimize?

Thanks,
/*
Matt Darland
dontspamme DOT mtd5922 AT omega DOT uta DOT edu
remove dontspamme to reply, or post a follow up. I read this group
VERY regularly.
*/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019