home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!darwin.sura.net!gatech!enterpoop.mit.edu!eru.mt.luth.se!lunic!sunic!aun.uninett.no!nuug!ifi.uio.no!sverrehu
- From: sverrehu@ifi.uio.no (Sverre H. Huseby)
- Newsgroups: comp.os.msdos.programmer
- Subject: Bug in Borland C++ & AF 3.1 ???
- Message-ID: <1993Jan7.134659.11109@ifi.uio.no>
- Date: 7 Jan 93 13:46:59 GMT
- Sender: sverrehu@ifi.uio.no (Sverre H. Huseby)
- Organization: Dept. of Informatics, University of Oslo, Norway
- Lines: 104
- Nntp-Posting-Host: holmenkollen.ifi.uio.no
- Originator: sverrehu@holmenkollen.ifi.uio.no
-
-
- Does anybody know anything about this?
- Please email any responses to me!
-
- --- CUT ---
-
- /**************************************************************************
- *
- * File: INLINE.CPP
- *
- * Written by:
- * Sverre H. Huseby
- * Bjoelsengt. 17
- * N-0468 Oslo
- * Norway
- *
- * sverrehu@ifi.uio.no
- *
- *
- * Possible bug in Borland C++ & AF v3.1 when expanding two calls
- * to the same inline function in one statement.
- *
- * Compiled with
- *
- * BCC inline.cpp
- *
- * with TURBOC.CFG containing
- *
- * -IC:\BORLANDC\INCLUDE
- * -LC:\BORLANDC\LIB
- *
- * The statement
- *
- * tmp = Stk.Pop() + Stk.Pop();
- *
- * in main() pops the first number twice, since the inline expansion
- * starts with _two_ dec of the stackindex.
- *
- **************************************************************************/
-
-
-
- #include <stdio.h>
-
-
-
- #define STACK_SIZE 10 // Max number of elements on the stack.
-
- class Stack {
-
- int Element[STACK_SIZE]; // The stack itself.
- int SP; // Stack Pointer. Index to next free pos.
-
- public:
- Stack() { Clear(); };
-
- void Clear() { SP = 0; };
- void Push(int x) { Element[SP++] = x; };
- int Pop() { return Element[--SP]; };
- };
-
-
- void main()
- {
- Stack Stk;
- int tmp;
-
-
- Stk.Push(2);
- Stk.Push(5);
- tmp = Stk.Pop() + Stk.Pop();
- printf("2 + 5 = %d", tmp); // Gives: 2 + 5 = 4
- }
-
-
- /**************************************************************************
- *
- * From INLINE.ASM compiled with
- *
- * BCC -S inline.cpp
- *
- * (the asterisk (*) and the exclamation point (!) are added `manually')
- *
- * ;
- * ; tmp = Stk.Pop() + Stk.Pop();
- * ;
- * dec word ptr [bp-4]
- * * dec word ptr [bp-4]
- * mov bx,word ptr [bp-4]
- * shl bx,1
- * lea ax,word ptr [bp-24]
- * add bx,ax
- * mov ax,word ptr [bx]
- * ! mov bx,word ptr [bp-4]
- * shl bx,1
- * lea dx,word ptr [bp-24]
- * add bx,dx
- * add ax,word ptr [bx]
- * mov word ptr [bp-2],ax
- *
- * The second dec (*) should (if I understand this correctly) have been
- * moved to before the line with a ! in the front.
- *
- **************************************************************************/
-