From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1164f8,9619a7b956b3cb13 X-Google-Attributes: gid1164f8,public X-Google-Thread: fee84,9619a7b956b3cb13 X-Google-Attributes: gidfee84,public X-Google-ArrivalTime: 1994-03-18 11:14:45 PST Xref: gmd.de comp.unix.osf.osf1:2596 comp.sys.dec:14490 Path: gmd.de!newsserver.jvnc.net!darwin.sura.net!howland.reston.ans.net!agate!msuinfo!harbinger.cc.monash.edu.au!bunyip.cc.uq.oz.au!dingo.cc.uq.oz.au!coates From: coates@kelvin.physics.uq.oz.au (Tony Coates) Newsgroups: comp.unix.osf.osf1,comp.sys.dec Subject: Re: DEC AXP (Alpha) c89 bug Date: 18 Mar 94 11:14:45 Organization: Department of Physics, The University of Queensland Message-ID: References: Reply-To: coates@physics.uq.oz.au NNTP-Posting-Host: kelvin.physics.uq.oz.au In-reply-to: cmr@world.std.com's message of Thu, 17 Mar 1994 11:37:50 GMT In article cmr@world.std.com (Charles M Richmond) writes: coates@kelvin.physics.uq.oz.au (Tony Coates) (*me*) writes: >We just received the DEC AXP (Alpha) c89 compiler as part of DEC's cxx >C++ compiler package. We are running OSF/1.3. I tried recompiling an >old program which compiled under cc and ran correctly. However, after >compilation with c89, the program failed. Debugging with dbx, and >with the aid of a few printf statements which I had to add, I found >that, when compiled with c89, a switch statement of the form > switch() { > case -1: ; break; > case 1: ; break; > default: > } >was reaching the default statement, even though the function >evaluation yielded -1. The same statement selected the -1 case when >compiled with cc. If you would provide us with an "actual" failing case (bad pun) then the net might be able to help. I would guess that your function evaluation and your case data use different types. Personally, I like c89. Well, I didn't provide the actual case, because I thought it too long, but I will now. The function returns a `signof' value - if this isn't an integer, then I'll be amused. The evalutaion is a bit compicated, but runs as follows. The switch that fails looks like switch(key_compare(p_tbky,p_tb->ca_p_parent->p_key)) { case -1: p_tb->ca_p_parent->p_left =p_new; break; case 1: p_tb->ca_p_parent->p_right=p_new; break; default: as_bomb("tb_ins: Key comparison function is inconsistent."); } and runs through to the default case when the function returns -1 (only under c89, not under cc. It works under cc). keycompare is a macro, defined as follows: #define key_compare(a,b) ((*(p_tb->p_kycm))((a),(b))) The particular function `p_kycm' which is called in the failing case is the following: LOCAL sign cm_name P_((name_t *,name_t *)); LOCAL sign cm_name(name1,name2) /* Compares two names and returns: */ /* -1 if name1 < name2 */ /* 0 if name1 = name2 */ /* 1 if name1 > name2 */ /* Provides a full ordering on the set of names. */ name_t *name1; name_t *name2; { return signof(strcmp(&(*name1)[0],&(*name2)[0])); } where the P_ macro just serves here to create an ANSI prototype, and the name_t structure is a fixed length array of characters. As I noted, this fails when compiled under c89, not cc, on a DEC AXP running OSF/1.3. I haven't attempted to try to convert this to a trivial example to check under what conditions it can occur, because changing back from c89 to cc is less effort for me than trying to create an example where it fails. Given that switch statements usually work, I can only hypothesise that this is a bug which doesn't arise in simple test programs, only in larger programs. Cheers, Tony. -- _____________________________________________________________________________ A.B.Coates, Dept. of Physics, The University of Queensland QLD 4072 Australia. Email: coates@physics.uq.oz.au Phone: (07/+617) 365-3424 Fax: (07/+617) 365-1242 Disclaimer: The University is ignorant of my opinions, let alone guilty ... _____________________________________________________________________________