[comp.sys.ibm.pc] Turbo C BUG in inline functions

markg@amd.UUCP (Mark Gorlinsky) (06/26/87)

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 <dos.h>
#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.