Article View: gnu.gcc.bug
Article #6360const pointer problem with gcc 2.7.x (repost)
From: Andrew Fyfe
Date: Mon, 04 Dec 1995 00:00
Date: Mon, 04 Dec 1995 00:00
40 lines
1288 bytes
1288 bytes
The following bug report relates to the following systems:
gcc 2.7.0 under Sun Sparc Solaris 2.4
gcc 2.7.2 under Sun Sparc Solaris 2.4
gcc 2.7.0 under Sun Sparc SunOS 4.1.4
gcc 2.7.0 under IBM PowerPC AIX 3.2.5
In all cases the only option given to gcc was "-O".
------------------------------------------------------------------------
With gcc 2.7.x, the optimizer considers the pointer dereference to
be a constant, and moves the dereference outside the loop. This is
not the behaviour of 2.6.3. The code below is reduced from a much
larger program.
Andy Fyfe
bandr@best.com
static void
set(char *x)
{
*x = 'x';
}
main()
{
int i;
char x = '\0';
for (i=0; i<10; ++i) {
set(&x);
if (*(const char *)&x != 'x') {
printf("Error!\n");
exit(1);
}
}
printf("OK!\n");
exit(0);
}
Technical Details
Message-ID:
<199512040625.GAA26514@shellx.best.com>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 113d02,e43d61a2a4062977,start X-Google-Attributes: gid113d02,public From: bandr@best.com (Andrew Fyfe) Subject: const pointer problem with gcc 2.7.x (repost) Date: 1995/12/04 Message-ID: <199512040625.GAA26514@shellx.best.com> X-Deja-AN: 121063376 distribution: gnu sender: daemon@cis.ohio-state.edu organization: GNUs Not Usenet newsgroups: gnu.gcc.bug