[comp.sys.ibm.pc] Turbo-C bug

jose@anasazi.UUCP (Jose Vasconcellos) (09/21/87)

The following code does not expand properly. This bug is found in
tc, tcc, and cpp.

#define MACRO(a)		/* comment */

xyz()
{
	MACRO(1);
}

This expands to

xyz()
{
	/;
}

If the comment is removed the expansion is processed correctly. Also, if
there is more than 1 argument it works properly.

hobbes@Portia.Stanford.EDU (Andrew Zimmerman) (05/31/89)

The following program doesn't run when compiled under Turbo-C 2.0.
(It does compile under Turbo-C, and it runs under Zortech C.)
Does anyone know if you can explicitly tell Turbo-C 2.0 to link in
the floating formats?

Andrew
hobbes@portia.stanford.edu

#include <stdio.h>
main()
{
    double a[3][3];
    int i;

    i = 1;
    scanf("%lf",&a[i][1]);
    printf("a[1][1] = %lf\n",a[1][1]);
}

scotth@grebyn.COM (Scott Hutchinson) (05/31/89)

In article <2556@Portia.Stanford.EDU> hobbes@Portia.Stanford.EDU (Andrew Zimmerman) writes:
>The following program doesn't run when compiled under Turbo-C 2.0.
>(It does compile under Turbo-C, and it runs under Zortech C.)
>Does anyone know if you can explicitly tell Turbo-C 2.0 to link in
>the floating formats?
>

	I believe adding the following function will do it.

void ___NeverUsed (float a, double b)
{
	return ( a * b * 1.01)
}

	

>main()
>{
>    double a[3][3];
>    int i;
>
>    i = 1;
>    scanf("%lf",&a[i][1]);
>    printf("a[1][1] = %lf\n",a[1][1]);
>}


-- 
                                     -Scott H. Hutchinson
Standard Disclamers:  These opinions are mine, they do not reflect on my
                      Company at all.
I can be reached at scotth@grebyn.com or grebyn!scotth

jacobs%cmos.utah.edu@wasatch.utah.edu (Steven R. Jacobs) (05/31/89)

In article <2556@Portia.Stanford.EDU> hobbes@Portia.Stanford.EDU (Andrew Zimmerman) writes:
>The following program doesn't run when compiled under Turbo-C 2.0.
>(It does compile under Turbo-C, and it runs under Zortech C.)
>Does anyone know if you can explicitly tell Turbo-C 2.0 to link in
>the floating formats?

I don't know about explicitly, but you can fake out the compiler as
shown in the modified example below.  I've seen problems similar to
this in Turbo-C 1.5 as well as 2.0, and they have problems getting
it right with structures that have float/double elements.

#include <stdio.h>
main()
{
    double a[3][3], tc_kludge;
    int i;

    i = 1;
    scanf("%lf", &tc_kludge);
    a[i][1] = tc_kludge;
    printf("a[1][1] = %lf\n",a[1][1]);
}

This trick need only appear at one point in the program, so luckily
you don't need to modify all 18,324 scanf() calls :-)


Steve Jacobs  ({ihnp4,decvax}!utah-cs!jacobs, jacobs@cs.utah.edu)

mju@mudos.ann-arbor.mi.us (Marc Unangst) (05/31/89)

In article <2556@Portia.Stanford.EDU>, hobbes@Portia.Stanford.EDU (Andrew Zimmerman) writes:
 >The following program doesn't run when compiled under Turbo-C 2.0.
 >(It does compile under Turbo-C, and it runs under Zortech C.)
 >Does anyone know if you can explicitly tell Turbo-C 2.0 to link in
 >the floating formats?
[example program deleted]

If you want to use the floating-point emulation package, use the -f
command line switch, or go to the Options Linker menu and flip
"Floating Point" to "Emulated".  For the 80x87 library, either use
the -f87 switch, or go to the Options Linker menu and flip "Floating
Point" to "80x87".  RTFM.

--  
Marc Unangst
UUCP smart    : mju@mudos.ann-arbor.mi.us
UUCP dumb     : ...!uunet!sharkey!mudos!mju
UUCP dumb alt.: ...!{ames,rutgers}!mailrus!clip!mudos!mju
Internet      : mju@mudos.ann-arbor.mi.us

rwmira01@ULKYVX.BITNET (Rob Miracle) (05/31/89)

In article <2556@Portia.Stanford.EDU> hobbes@Portia.Stanford.EDU (Andrew
  Zimmerman) writes:
>
>The following program doesn't run when compiled under Turbo-C 2.0.
>(It does compile under Turbo-C, and it runs under Zortech C.)
>Does anyone know if you can explicitly tell Turbo-C 2.0 to link in
>the floating formats?
>

There is a compiler bug in Turbo-C V2.0 dealing with this problem.
[s,v,f]scanf() does not notify the linker that it needs the floating point
library.  Borland has issued a patch and it is download-able from CompuServe
(their offical support thingy).  I suspect that any Service with a Borland Sig
will have a copy of the patches.  I also saw them come over netnews a few
months ago.

For this one problem, you can also put in a line

   double x;

   x = 1.0;

and that should fix it, if you do it before the scanf I believe.  Get the
patches if you can.

Rob
--
Rob Miracle              | Bitnet   : RWMIRA01@ULKYVX    CIS: 74216,3134
Programmer/Analyst-II    | INTERNET : rwmira01%ulkyvx.bitnet@cunyvm.cuny.edu
University of Louisville | UUCP     : ...psuvax1!ulkyvx.bitnet!rwmira01
"Many truths that we cling to are only true from a certain point of view."
      -- Ob-Wan Kenobi

matthew@sunpix.UUCP ( Sun Visualization Products) (05/31/89)

I'm was taking a "C" programmers course at a local community college, and your
trouble sounds like a problem we (my class) were having using 'scanf' under
Turbo-C version 2.0.  Heres the fix we received (near verbatium):

~The fix is to include a call to any function (including 'scanf') and pass
~the address of a simple float as a parameter. Add the following lines to 
~your program.
~
~static void bogus(void)   /* dummy routine to fix TC-2.0 float problem */
~    {                     /* DO NOT CALL THIS FUNCTION!!!!!!!!!!!!!!!! */
~    float f;
~    scanf(&f);
~    }

I also remember reading that the problem had to do with referencing '_turbofloat',
or something like that.


-- 
Matthew Lee Stier                         |
Sun Microsystems ---  RTP, NC  27709-3447 |        "Wisconsin   Escapee"
uucp: { sun, mcnc!rti }!sunpix!matthew    |
phone: (919) 469-8300 fax: (919) 460-8355 |

thorp@spudge.UUCP (Don Thorp) (05/31/89)

In article <2556@Portia.Stanford.EDU> hobbes@Portia.Stanford.EDU (Andrew Zimmerman) writes:
>The following program doesn't run when compiled under Turbo-C 2.0.
>(It does compile under Turbo-C, and it runs under Zortech C.)
>Does anyone know if you can explicitly tell Turbo-C 2.0 to link in
>the floating formats?
>
#include <stdio.h>
main()
{
    double a[3][3];
    int i;

    /* ----- Fix for linking in floating point library -----
     * _turboFloat() is never called, it forces the FLOAT library to be
     *  linked into the program.
     */
    if (0)
      _turboFloat();

    i = 1;
    scanf("%lf",&a[i][1]);
    printf("a[1][1] = %lf\n",a[1][1]);
}

Try adding the above statement to your code.  It should fix the problem.  I
compiled your program using TC2.0 and it worked, but I've applied a number
of patches and one of them could have fixed the problem.

Don Thorp

few@quad1.quad.com (Frank Whaley) (06/02/89)

In article <2556@Portia.Stanford.EDU> hobbes@Portia.Stanford.EDU (Andrew Zimmerman) writes:
>The following program doesn't run when compiled under Turbo-C 2.0.

Ooh, an interesting bug I hadn't seen before.  Yes, when TC realizes that
floating-point library code should be included, it puts a reference to the
external symbol __turboFloat into the object file.  This reference causes
the f-p code to be loaded.  You found a case where this was overlooked.
I got around the problem by adding the line:
	static void UNUSED(){_turboFloat();}
to the source file.  This kludge requires only 4 bytes for small code
models (CALL 0000;RET) and 6 for large code models.

-- 
Frank Whaley
Senior Development Engineer
Quadratron Systems Incorporated
few@quad1.quad.com
uunet!ccicpg!quad1!few

Water separates the people of the world;
Wine unites them.

pjh@mccc.UUCP (Pete Holsberg) (06/05/89)

I just mailed the latest Turbo C 2.0 patch file to Rahul, along with the
needed patching program.  I'm sure he will post both in c.b.i.p, post
haste.
-- 
Pete Holsberg, Prof., Technology Div., Mercer Cnty College, Trenton, NJ 08690  
{backbone}!rutgers!njin!princeton!njsmu!mccc!pjh

hovanes@db.UUCP (Kenneth Hovanes) (06/08/89)

I was wondering if anybody out there knew of a clean way to throw a series
of graphics buffers onto the screen using assembly.  I am writing an animation
routine, primary in C, and would like to use assembly to toss the stuff to
the screen.  This is for an IBM clone.

I have consulted several manuals on animation in assembly but none deal
with the EGA screens.  They are all concerned with the CGA screen.  I have
no problem doing the basic point plots in assembly, but, and this is a big
but, I cannot make sense of trying to throw a graphics buffer to the EGA
screen.  There are four planes of color, and from what I understand each
has to done by itself. Please correct me if I am wrong.  By having to plot on
each bit plane, one at a time, I figure the loss of speed is tremendous,
even though pc's are slow anyway.

If anyone has any suggestions please post them.

________________________________________________________________________________
    ____________                                      |When  Hydrogen  U  played
   /   ----    /|                                     |Oxygen   Tech,  the  game
  /     --/   / |                                     |had  just begun. Hydrogen
 /   ____/   /  |  Kenneth Hovanes, Informix Analyst  |racked up two fast points
/___________/ /||  Intergraph Corporation             |Oxygen  still  had  none.
|           |/ ||  One Madison Park                   |Oxygen  scored  a  single
|    /|     | / |  Huntsville, AL   35816             |goal  and  thus   it  did
|     |     || /|  (205) 772-7938                     |remain     Hydrogen    2,
|     |     ||/ !                                     |Oxygen 1, called  because
|     |     |  /                                      |of rain.  (unknown)
|   __!__   | /                                       !_________________________
!___________!/    UUCP:  uunet!ingr!db!hovanes
________________________________________________________________________________

vail@tegra.UUCP (Johnathan Vail) (06/12/89)

In article <203@db.UUCP> hovanes@db.UUCP (Kenneth Hovanes) writes:

   I was wondering if anybody out there knew of a clean way to throw a series
   of graphics buffers onto the screen using assembly.  I am writing an animation
   routine, primary in C, and would like to use assembly to toss the stuff to
   the screen.  This is for an IBM clone.

   I have consulted several manuals on animation in assembly but none deal
   with the EGA screens.  They are all concerned with the CGA screen.  I have
   no problem doing the basic point plots in assembly, but, and this is a big
   but, I cannot make sense of trying to throw a graphics buffer to the EGA
   screen.  There are four planes of color, and from what I understand each
   has to done by itself. Please correct me if I am wrong.  By having to plot on
   each bit plane, one at a time, I figure the loss of speed is tremendous,
   even though pc's are slow anyway.

   If anyone has any suggestions please post them.

EGA has lots of funny registers and modes.  This makes it difficult to
learn but provides a lot of capability.  Certainly the mapping is
easier than the CGA.  In one mode you can write to a bit plane.  In
another youcan select a color and then write that color at screen
locations, the EGA will write all the planes for you at once.

Here are some *very* simple EGA routines that I have for some programs
I am working on.  The routines here will draw various colored bodes on
the screen and draw some icons.  Hopefully this will help.

"Always Mount a Scratch Monkey"
 _____
|     | Johnathan Vail | tegra!N1DXG@ulowell.edu
|Tegra| (508) 663-7435 | N1DXG@145.110-,145.270-,444.2+,448.625-
 -----


	title	scan
; History:520,1
.286C

;______________________________________________________________________________
;
;	SCAN	Display a spectrum scan
;
;	WRITTEN:	Johnathan Vail, N1DXG
;
;	31 Oct 1988 jv	- Create from wx sources
;______________________________________________________________________________


stuff	macro	a,d
	mov	dx,3CEh			; graphics 1 & 2 Address Register
	mov	al,a
	out	dx,al
	mov	dx,3CFh			; data io address selcted with above
	mov	al,d
	out	dx,al
	endm

;______________________________________________________________________________
;

;
;	Paramaters to control the display format:
;
pixels_per_line	equ	640
num_lines	equ	350

color_bar_chars	equ	2
color_bar_lines	equ	color_bar_chars*14
color_bar_size	equ	4			; bytes per line

mickey:
	mov	bl,16			; EGA Graphics 640x350 by 16 of 64
	call	set_mode

	mov	ax,ega_seg		; Fill the screen with a color
	mov	es,ax
	mov	di,0			; top_line_addr
	cli
	stuff	5,2			; mode select register, mode 2
	mov	al,es:[di]
	stuff	8,0ffh			; Bit mask register, all bits
	mov	al,acolor
	mov	es:[di],al
	mov	al,es:[di]
	stuff	5,1
	mov	cx,(color_bar_lines + num_lines)*40
	cld
	rep	stosw

	mov	si,offset scan_icon	; display logo
	mov	di,0
	call	paint_icon
	mov	si,offset file_icon	; and file icon for future
	mov	di,4
	call	paint_icon


;______________________________________________________________________________
;	mode in bl
set_mode proc near
	push	es

	mov	ax,40h
	mov	es,ax
	mov	al,bl

	mov	bl,BYTE PTR es:10h
	and	bl,0EFh
	or	bl,20h
	cmp	al,7		; Set the configuration byte
	jne	not_a_mono
	or	bl,30h
not_a_mono:
	mov	BYTE PTR es:10h,bl
	mov	ah,0
	int	10h

	pop	es
	ret
set_mode	endp



;______________________________________________________________________________
;
;	EGA Graphics Routines
;

;
;	Vertical line
;
;	ax	= x coor (from left)
;	es:di	= addr of y (from top)
;	bl	= color
;	dx	= distance
;
;	vertical_color		Entry to continue line with new color & count
;
;	bl	= color
;	dx	= distance
;
vertical_line:
	push	ax
	shr	ax,1			; div by 8 for byte offset of x
	shr	ax,1
	shr	ax,1
	add	di,ax
	pop	ax
	and	al,7
	mov	cl,al
	mov	ah,80h
	jz	vertical_color
	shr	ah,cl
vertical_color:
	mov	cx,dx			; loop count
	stuff	5,2			; mode select register, mode 2
	mov	al,es:[di]
	stuff	8,ah			; Bit mask register
	mov	al,bl
	mov	es:[di],al
	mov	al,es:[di]
	stuff	5,1
vline:	mov	es:[di],al		; al doesn't matter
	add	di,80			; bytes per scan line
	loop	vline
	ret


icon_foreground	equ	0fh
icon_background	equ	0

;
;	Paint Icon
;
;	Enter: ds:si = icon addr,  es:di = screen addr (both upper left)
;
paint_icon:
	push	di
	mov	bl,icon_background
	call	color_bar
	pop	di
	mov	bh,28
icon_loop:
	mov	cx,4
icon_line:
	stuff	5,2			; mode select register, mode 2
	mov	al,es:[di]
	mov	bl,[si]
	inc	si
	stuff	8,bl			; Bit mask register, all bits
	mov	al,icon_foreground
	mov	es:[di],al
	mov	al,es:[di]
	inc	di

	loop	icon_line
	add	di,80-4
	dec	bh
	jnz	icon_loop
	stuff	5,0			; Set ega mode back...
	sti
	ret


;______________________________________________________________________________
;
;	bl has color, di has top left addr
;
color_bar:
	stuff	5,2			; mode select register, mode 2
	mov	al,es:[di]
	stuff	8,0ffh			; Bit mask register, all bits
	mov	al,bl
	mov	es:[di],al
	mov	al,es:[di]
	stuff	5,1
	mov	bh,color_bar_lines
byte_loop:
	mov	cx,color_bar_size
rep	stosb
	add	di,80-color_bar_size
	dec	bh
	jnz	byte_loop
	ret

;
;	ICONS:
;

;______________________________________________________________________________
;
;	14 rows by 32 bits across, 0=background, 1=foreground
;
scan_icon	label byte

	db	11111111b,11111111b,11111111b,11111111b
	db	11111111b,11111111b,11111111b,11111111b
	db	11110000b,11111111b,11111111b,11111111b
	db	11110111b,11111111b,11111111b,11111111b
	db	11110111b,11111100b,11111111b,11111111b
	db	11110000b,10001111b,01100011b,11111111b
	db	11111110b,10111000b,01101101b,11111111b
	db	11111110b,10111010b,01101101b,11111111b
	db	11110000b,10001101b,00101101b,11111111b
	db	11111111b,11111111b,11111111b,11111111b
	db	11111111b,11111111b,11111111b,11111111b
	db	11111111b,11111111b,11111111b,11111111b
	db	11111111b,11111111b,11111111b,11111111b
	db	11111111b,11111111b,11111111b,11111111b

	db	11111111b,11111111b,11111111b,11111111b
	db	11111111b,11111111b,11111111b,11111111b
	db	11111111b,11111111b,11111111b,11111111b
	db	11111111b,11111111b,11111111b,11111111b
	db	11011101b,10110001b,10110110b,00111111b
	db	11001101b,00110100b,10110101b,11111111b
	db	11010101b,10110110b,11001101b,11111111b
	db	11010101b,10110110b,11001101b,00111111b
	db	11011001b,10110100b,10110101b,10111111b
	db	11011101b,00010001b,10110100b,01111111b
	db	11111111b,11111111b,11111111b,11111111b
	db	11111111b,11111111b,11111111b,11111111b
	db	11111111b,11111111b,11111111b,11111111b
	db	11111111b,11111111b,11111111b,11111111b

file_icon	label byte
	db	11111111b,11111111b,11111111b,11111111b
	db	10000000b,00000000b,00000000b,00000001b
	db	10111111b,11111111b,11111111b,11111101b
	db	10100000b,00000000b,00000000b,01111101b
	db	10101111b,11111111b,11111111b,01111101b
	db	10101111b,11111111b,11111111b,01110001b
	db	10101111b,11111111b,11111111b,01110001b
	db	10101111b,11111111b,11111111b,01111101b
	db	10100000b,00000000b,00000000b,01111101b
	db	10111111b,11111111b,11111111b,11111101b
	db	10111111b,11111111b,11111111b,11111101b
	db	10111111b,11111110b,00111111b,11111101b
	db	10111111b,11111100b,00011111b,11111101b
	db	10111111b,11111000b,00001111b,11111101b
	db	10111111b,11101000b,00001111b,11111101b
	db	10111111b,11111000b,00001111b,11111101b
	db	10111111b,11111100b,00011111b,11111101b
	db	10111111b,11111110b,00111111b,11111101b
	db	10111111b,11111111b,11111111b,11111101b
	db	10111111b,11111111b,11111111b,11111101b
	db	10111111b,11111111b,01111111b,11111101b
	db	10111111b,11111110b,00111111b,11111101b
	db	10111111b,11111110b,00111111b,11111101b
	db	10111111b,11111110b,00111111b,11111101b
	db	10111111b,11111111b,01111111b,11111101b
	db	10111111b,11100111b,11111001b,11111101b
	db	10000000b,00000000b,00000000b,00000001b
	db	11111111b,11111111b,11111111b,11111111b