This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: egcs-2.91.55 19980824 error on const references


Hyman Rosen <hymie@prolifics.com> writes:
> 
> I don't mean to be obnoxious, but I'm going to keep on reporting this
> until someone out there fixes it, or adds a test case for it, or at
> least acknowledges its existence.
> 
Interesting.  :-(

> extern "C" int printf(const char *, ...);
> int main(int, char **)
> {
> 	volatile const int c = 42;
> 	volatile int *p;
> 	volatile const int *&r = p;
> 	r = &c;
> 	*p = 0;
> 	if (c != 42)
> 		printf("FAILED!\n");
> }

It gets even more interesting if you move the three declarations out of
main():
$ cat x.cc
extern "C" int printf(const char *, ...);
volatile const int c = 42;
volatile int *p;
volatile const int *&r = p;

int main(int, char **)
{

        r = &c;
        *p = 0;
        if (c != 42)
                printf("FAILED %d!\n",c);
}
$ gcc -o x x.cc ; ./x
FAILED 0!
$ gcc -Dvolatile= -o x x.cc ; ./x ## actually, it's the third volatile
Segmentation fault

Duh.

Optimization or not made no difference.

-- 
Matthias Urlichs
noris network GmbH


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]