🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #5986

(no subject given!)

#5986
From: Bret Indrelee
Date: Mon, 20 Jan 1997 00:00
58 lines
2368 bytes
Newsgroups: gnu.gcc.bug
Path: breti
From: breti@bit3.com (Bret Indrelee)
Subject: Re: gcc 272 pointer bug
Message-ID: <E4Br2p.AFC@bit3.com>
Date: Mon, 20 Jan 1997 20:47:13 GMT
References: <970120092332_1510729510@emout20.mail.aol.com>
Organization: Bit 3 Computer Corp

In article <970120092332_1510729510@emout20.mail.aol.com>,
 <Labalutsch@aol.com> wrote:
[ snip ]
>char *
>force_bug( p, pres)
>  char	*p;
>  int	*pres;
>{
>  /* gcc-2.7.2 will produce code like the following statements were given:
>   *   *pres= ( (unsigned char) *p << 8) | (unsigned char) *p;
>   *   return( p+ 2);
>   * gcc-2.7.2 would produce correct code if the sequence would be:
>   *   *pres= (unsigned char) *p++ << 8;
>   *   *pres |= (unsigned char) *p++;
>   *   return( p);
>   * but this sequence can't be used as a while-expression
>   */
>
>  *pres= ( (unsigned char) *p++ << 8) | (unsigned char) *p++;
>  return( p);
>}
>
>/* --- C code ends here --- */
>
>IMHO, the evaluation order for the `bitwise-or' operator is left to right.
>At least according to K&R.  Additionally the left-hand side of the `or'
>operator is parenthesized giving it highest priority.  Side-effects aren't
>an argument, as no function call is involved here.  Neither is the
>incremented
>pointer an l-value in this case.  So the above sequence is correct, at least
>to my understanding of C programming.

[ snip ]

In ANSI C, your code does not give well defined behaviour.

It is not correct because there is no sequence point between the two 
post-increment operations on the same data object. Side effects are not 
defined between sequence points.

The comma, conditional, function call, logical AND and logical OR operators
contain a sequence point. Notice that the bitwise AND and bitwise OR do not
imply a sequence point within an expression.

-Bret
-- 
Bret Indrelee
breti@bit3.com		#include <std_disclaimer.h>
Technical Details
Message-ID: <m0vmQce-000UOcC@bit3.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 113d02,8f2e1edcf7890a83,start
X-Google-Attributes: gid113d02,public
From: breti@bit3.com (Bret Indrelee)
Subject: (no subject given!)
Date: 1997/01/20
Message-ID: <m0vmQce-000UOcC@bit3.com>
X-Deja-AN: 211122059
sender: bug-gcc-request@prep.ai.mit.edu
x-gateway: relay6.UU.NET from bug-gcc to gnu.gcc.bug; Mon, 20 Jan 1997 16:02:12 EST
newsgroups: gnu.gcc.bug