Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!ll-xn!ames!amdcad!amd!markg From: markg@amd.UUCP (Mark Gorlinsky) Newsgroups: comp.sys.ibm.pc Subject: Turbo C BUG in inline functions Message-ID: <4146@amd.UUCP> Date: Fri, 26-Jun-87 13:11:53 EDT Article-I.D.: amd.4146 Posted: Fri Jun 26 13:11:53 1987 Date-Received: Sat, 27-Jun-87 10:46:23 EDT Reply-To: markg@amdcad.UUCP (Mark Gorlinsky) Organization: Advanced Micro Devices Lines: 59 Keywords: turboc, bug References: ==================================================================== The following is a code fragment from a terminal emulator I'm writing using Turbo C. As you can see I'm attempting to mask the input from a port with a constant value and then outputting the results back to the same port. If you look at the assembly language output you will notice a PUSH DX in the code without matching POP ??. It looks like the compile couldn't decide whether or not port_base needed to be saved, so it did both a save and a reload, and then didn't do the restore because it did the reload. This is clearly a BUG in the way Turbo C handles "inline" functions. The only way to avoid this BUG is to seperate the two functions and use a temporary variable for holding the return value of the inportb function. ======================================================================== #include #define DTR 1 #define RTS 2 void foo() { int port_base; port_base = 0x3F8; outportb(port_base+4, inportb(port_base+4) & ~(DTR+RTS)); } ======================================================================== ... ; Line 7 _foo proc near push si ; Line 10 mov si,1016 ; Line 11 mov dx,si add dx,4 in al,dx and al,-4 push dx mov dx,si add dx,4 out dx,al ; Line 12 @1: pop si ret _foo endp end ... -- Mark Gorlinsky - AMD Processor Products Division/APPS SQA UUCP: {decwrl,ihnp4,allegra}!amd!markg AT&T: (408) 982-7811 DISCLAIMER: My opinions are mine, not my employers.