[openbeos] possible gcc bug ?
- From: Stefano Ceccherini <burton666@xxxxxxxxxxx>
- To: openbeos@xxxxxxxxxxxxx
- Date: 27 Jun 2005 17:33:53 -0000
I found a weird behaviour of gcc. I don't know if it's normal, and I'd like
someone more "in the know" than me to explain :)
This code:
#include <stdio.h>
static int sInc = 0;
static int sDec = 0;
static int sCounter = 0;
static void
do_stuff()
{
int &ref = sInc;
ref++;
ref = sDec;
ref--;
sCounter++;
printf("inc: %d (should be %d), dec: %d (should be %d)\n",
sInc, sCounter, sDec, -sCounter);
}
int main()
{
for (int i = 0; i < 10; i++)
do_stuff();
}
Results in this printout:
inc: -1 (should be 1), dec: 0 (should be -1)
inc: -1 (should be 2), dec: 0 (should be -2)
inc: -1 (should be 3), dec: 0 (should be -3)
inc: -1 (should be 4), dec: 0 (should be -4)
inc: -1 (should be 5), dec: 0 (should be -5)
inc: -1 (should be 6), dec: 0 (should be -6)
inc: -1 (should be 7), dec: 0 (should be -7)
inc: -1 (should be 8), dec: 0 (should be -8)
inc: -1 (should be 9), dec: 0 (should be -9)
inc: -1 (should be 10), dec: 0 (should be -10)
Am I dumb if I think it should be different or it's a bug in our gcc ?
---------------------------------------------------------------
Scegli il tuo dominio preferito e attiva la tua email! Da oggi
l'eMail di superEva e' ancora piu' veloce e ricca di funzioni!
http://webmail.supereva.it/new/
---------------------------------------------------------------
- Follow-Ups:
- [openbeos] Re: possible gcc bug ?
- From: Michael Pfeiffer
- [openbeos] Re: possible gcc bug ?
- From: Korli
- [openbeos] Re: possible gcc bug ?
- From: Marcus Overhagen
Other related posts:
- » [openbeos] possible gcc bug ?
- » [openbeos] Re: possible gcc bug ?
- » [openbeos] Re: possible gcc bug ?
- » [openbeos] Re: possible gcc bug ?
- » [openbeos] Re: possible gcc bug ?
- » [openbeos] Re: possible gcc bug ?
- [openbeos] Re: possible gcc bug ?
- From: Michael Pfeiffer
- [openbeos] Re: possible gcc bug ?
- From: Korli
- [openbeos] Re: possible gcc bug ?
- From: Marcus Overhagen