🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #1042

Increment isn't done before assigment in unoptimized version

#1042
From: John Carlson
Date: Wed, 02 Sep 1992 09:01
31 lines
988 bytes
Machine: Sparcstation 2
OS: Sun OS 4.1.1
Compiler: gcc-2.2.2


The follow program gives difference result when compiled with
and without the -O option to gcc.

#include <stdio.h>
main ()
{
	int i = 0;
	i = i++;
	printf("should be 1->%d\n", i);
}


The unoptimized version prints:

should be 1->0

The optimized version prints:

should be 1->1

Guess the moral of the story is to use the optimized version.
Either that or I was too tired when programming.
(Yeay! The program works now!)

John Carlson
carlson@yottzumm.tis.llnl.gov
Technical Details
Message-ID: <135156@lll-winken.LLNL.GOV>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!tis.llnl.gov!carlson

Show Full Headers
Complete Article Headers
Newsgroups: gnu.gcc.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!tis.llnl.gov!carlson
From: carlson@tis.llnl.gov (John Carlson)
Subject: Increment isn't done before assigment in unoptimized version
Message-ID: <135156@lll-winken.LLNL.GOV>
Sender: gnulists@ai.mit.edu
Organization: Lawrence Livermore National Laboratory
Distribution: gnu
Date: Wed, 2 Sep 1992 09:01:55 GMT
Approved: bug-gcc@prep.ai.mit.edu
Lines: 32