*BSD News Article 82388


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.carno.net.au!harbinger.cc.monash.edu.au!news.mira.net.au!news.netspace.net.au!news.mel.connect.com.au!munnari.OZ.AU!news.ecn.uoknor.edu!feed1.news.erols.com!howland.erols.net!news.mathworks.com!solaris.cc.vt.edu!server.cs.vt.edu!not-for-mail
From: tjohnson@csgrad.cs.vt.edu (Tommy Johnson)
Newsgroups: comp.unix.bsd.freebsd.misc
Subject: Compiler bug?
Date: 6 Nov 1996 00:23:32 -0500
Organization: Virginia Tech, Blacksburg, Virginia
Lines: 38
Message-ID: <55p7ck$r2l@csgrad.cs.vt.edu>
NNTP-Posting-Host: csgrad.cs.vt.edu

This program doesn't work as I think it should.   On line 10, b is not 
incremented between the first and second b++'s, though it is correct
after the entire expression.

On FreeBSD 2.2-Current as of about Oct 13, the program below produces
0x1212 instead of 0x3412  (gcc 2.7.2.1, or gcc 2.6.3).  It also happens
on NetBSD 1.1B as of about May 16 on an HP300 (gcc 2.7.2).  It DOES produce
0x3412 on a DEC alpha with gcc 2.7.2, or gcc 2.7.2 on a DECstation
(OSF1 3.2 148, and Ultrix 4.4 rev 69 respectively).

(It also breaks on FreeBSD 2.1.5-Release with gcc 2.6.3)

Am I hallucinating?   TIA...
  
-Tom "Bugger, now I have to wait for someone to wake up." -Marcus
tjohnson@csgrad.cs.vt.edu  "My other computer ALSO runs unix." -me   <*>
http://csgrad.cs.vt.edu/~tjohnson/  Commercial email is unwelcome.
Message and signature (c) 1996 Tommy O. Johnson, all rights reserved

--- Bite Here --- Bite Here --- Bite Here ---

/* Copyright: test program, do with it as you wish
** Tommy Johnson
*/
main()
{
        int a,b;
        unsigned char c[2];

        b=0;
        c[0]=0x12;
        c[1]=0x34;

        a=c[b++]|((c[b++])<<8);
        printf("should be 0x3412 %4x\n",a);
}