home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / os / msdos / programm / 11856 < prev    next >
Encoding:
Text File  |  1993-01-07  |  2.8 KB  |  117 lines

  1. 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
  2. From: sverrehu@ifi.uio.no (Sverre H. Huseby)
  3. Newsgroups: comp.os.msdos.programmer
  4. Subject: Bug in Borland C++ & AF 3.1 ???
  5. Message-ID: <1993Jan7.134659.11109@ifi.uio.no>
  6. Date: 7 Jan 93 13:46:59 GMT
  7. Sender: sverrehu@ifi.uio.no (Sverre H. Huseby)
  8. Organization: Dept. of Informatics, University of Oslo, Norway
  9. Lines: 104
  10. Nntp-Posting-Host: holmenkollen.ifi.uio.no
  11. Originator: sverrehu@holmenkollen.ifi.uio.no
  12.  
  13.  
  14. Does anybody know anything about this?
  15. Please email any responses to me!
  16.  
  17. --- CUT ---
  18.  
  19. /**************************************************************************
  20.  *
  21.  *  File: INLINE.CPP
  22.  *
  23.  *  Written by:
  24.  *    Sverre H. Huseby
  25.  *    Bjoelsengt. 17
  26.  *    N-0468 Oslo
  27.  *    Norway
  28.  *
  29.  *    sverrehu@ifi.uio.no
  30.  *
  31.  *
  32.  *  Possible bug in Borland C++ & AF v3.1 when expanding two calls
  33.  *  to the same inline function in one statement.
  34.  *
  35.  *  Compiled with
  36.  *
  37.  *    BCC inline.cpp
  38.  *
  39.  *  with TURBOC.CFG containing
  40.  *
  41.  *    -IC:\BORLANDC\INCLUDE
  42.  *    -LC:\BORLANDC\LIB
  43.  *
  44.  *  The statement
  45.  *
  46.  *    tmp = Stk.Pop() + Stk.Pop();
  47.  *
  48.  *  in main() pops the first number twice, since the inline expansion
  49.  *  starts with _two_ dec of the stackindex.
  50.  *
  51.  **************************************************************************/
  52.  
  53.  
  54.  
  55. #include <stdio.h>
  56.  
  57.  
  58.  
  59. #define STACK_SIZE 10           // Max number of elements on the stack.
  60.  
  61. class Stack {
  62.  
  63.     int Element[STACK_SIZE];    // The stack itself.
  64.     int SP;                     // Stack Pointer. Index to next free pos.
  65.  
  66.   public:
  67.     Stack() { Clear(); };
  68.  
  69.     void Clear()     { SP = 0; };
  70.     void Push(int x) { Element[SP++] = x; };
  71.     int  Pop()       { return Element[--SP]; };
  72. };
  73.  
  74.  
  75. void main()
  76. {
  77.     Stack Stk;
  78.     int   tmp;
  79.  
  80.  
  81.     Stk.Push(2);
  82.     Stk.Push(5);
  83.     tmp = Stk.Pop() + Stk.Pop();
  84.     printf("2 + 5 = %d", tmp);  // Gives: 2 + 5 = 4
  85. }
  86.  
  87.  
  88. /**************************************************************************
  89.  *
  90.  *  From INLINE.ASM compiled with
  91.  *
  92.  *    BCC -S inline.cpp
  93.  *
  94.  *  (the asterisk (*) and the exclamation point (!) are added `manually')
  95.  *
  96.  *    ;
  97.  *    ;        tmp = Stk.Pop() + Stk.Pop();
  98.  *    ;
  99.  *         dec     word ptr [bp-4]
  100.  *       * dec     word ptr [bp-4]
  101.  *         mov     bx,word ptr [bp-4]
  102.  *         shl     bx,1
  103.  *         lea     ax,word ptr [bp-24]
  104.  *         add     bx,ax
  105.  *         mov     ax,word ptr [bx]
  106.  *       ! mov     bx,word ptr [bp-4]
  107.  *         shl     bx,1
  108.  *         lea     dx,word ptr [bp-24]
  109.  *         add     bx,dx
  110.  *         add     ax,word ptr [bx]
  111.  *         mov     word ptr [bp-2],ax
  112.  *
  113.  *  The second dec (*) should (if I understand this correctly) have been
  114.  *  moved to before the line with a ! in the front.
  115.  *
  116.  **************************************************************************/
  117.