[comp.sys.amiga] Aztec C bug

rico@oscvax.UUCP (11/17/87)

main()
{
	struct foo { int x; } bar;

	if (bar) ;
}

compiles to:

;main()
;{
	public	_main
_main:
	link	a5,#.2
	movem.l	.3,-(sp)
;	struct foo { int x; } bar;
;
;	if (bar) ;
	tst.r	-2(a5)		<----- Say what?   what's a .r???
	beq	.4
;}
.4
.5
	movem.l	(sp)+,.3
	unlk	a5
	rts
.2	equ	-2
.3	reg	
	public	.begin
	dseg
	end
-- 
		...{watmath|allegra|decvax|ihnp4|linus}!utzoo!oscvax!rico
		or oscvax!rico@gpu.toronto.EDU   if you're lucky

[NSA food: terrorist, cryptography, DES, drugs, CIA, secret, decode]
[CSIS food: supermailbox, tuna, fiberglass coffins, Mirabel, microfiche]
[Cat food: Nine Lives, Cat Chow, Meow Mix, Crave]

waterman@cory.Berkeley.EDU.UUCP (11/19/87)

 rico@oscvax.UUCP (Rico Mariani) writes:
>
> main()
> {
>	struct foo { int x; } bar;
>
>	if (bar) ;
> }
>
> compiles to:


    No. The only compiler bug here is that it didn't give you a big
flaming error message (multiple lines, ^'s and all, Mike :^).
    This is a program bug, not a compiler bug. 

    bar, being a structure, is not allowed as an argument to if().
bar cannot be zero, non-zero, or anything else. It is a label for a structure.
The only legal thing you can do here is to say:

    if (bar.x);

  What you have written really can't be said in C. C is a strange mixture
of high level and very-low level programming constructs, and as such it
can get you into some severe trouble.

   Hope this clears this one up.

	
	Happy bug-hunting !-)

	---TS

rchampe@hubcap.UUCP (Richard Champeaux) (11/19/87)

In article <532@oscvax.UUCP>, rico@oscvax.UUCP (Rico Mariani) writes:
> 
> main()
> {
> 	struct foo { int x; } bar;
> 
> 	if (bar) ;
> }
> 
> compiles to:
> 
> ;	if (bar) ;
> 	tst.r	-2(a5)		<----- Say what?   what's a .r???
> 	beq	.4

     I'm not an expert in C, but doesn't "if (bar)" mean "if (bar!=0)" and
its illegal to compare a structure to an integer even if the structure is
only an integer, (I could be wrong, like I said, I'm no expert.)
If I remember right, using a structure name alone does not give a pointer
to that structure like using the unsubscripted name of an array would.  To get
a pointer to the structure bar, you would use &bar.
(Once again, I could be wrong, I'm no expert.)
     Anyways, a simmilar thing happened to me a while back, I don't remember
the exact code but it had to do with structures and pointers. I got a 
move.x instead.
     I think it's less of a bug, and more of a very poor way to point out
errors.

Rich Champeaux
Clemson University

rico@oscvax.UUCP (11/22/87)

In article <4993@zen.berkeley.edu> waterman@cory.Berkeley.EDU.UUCP (T.S. Alan Waterman) writes:
>
> rico@oscvax.UUCP (Rico Mariani) writes:
>>
>> main()
>> {
>>	struct foo { int x; } bar;
>>
>>	if (bar) ;
>> }
>>
>> compiles to:
>
>    No. The only compiler bug here is that it didn't give you a big
>flaming error message (multiple lines, ^'s and all, Mike :^).

I know... that's the point.  I included the assembler output because
I thought it might help someone find the problem...

>    This is a program bug, not a compiler bug. 

No matter what I type at the compiler it should never produce invalid
assembler code.  Although if it's going to blow it, I'd much rather
that it produce code the assembler barfs on that quietly produce
code that's wrong.

	-Rico
-- 
		...{watmath|allegra|decvax|ihnp4|linus}!utzoo!oscvax!rico
		or oscvax!rico@gpu.toronto.EDU   if you're lucky

[NSA food: terrorist, cryptography, DES, drugs, CIA, secret, decode]
[CSIS food: supermailbox, tuna, fiberglass coffins, Mirabel, microfiche]
[Cat food: Nine Lives, Cat Chow, Meow Mix, Crave]

la086318@zach.fit.edu ( Mark R. Craig) (07/14/90)

I'm sure this has been covered before, but does anyone know why the 
following won't run correctly:

#include <stdio.h>
#include <math.h>

main()
{
float x,y;

printf("Enter x: ");
scanf("%f",&x);
printf("x=%f\n",x);
printf("Enter y: ");
scanf("%f",&y);
printf("y=%f\n",y);
}

it asks for x, you type in x, it prints x= (but no number), doesn't
go to next line, prints Enter y (but doesn't wait for keyboard input),
prints y= (but no number), and crashes.  I'm using Aztec C.  Any help
would be appreciated.

Mark R. Craig

Mark R. Craig
Internet:  la086318@zach.fit.edu
UUCP:      ...!winnie!zach!la086318

la086318@zach.fit.edu ( Mark R. Craig) (07/17/90)

I wanted to thank all of the people who replied to my question of
(what I thought to be) an Aztec C bug.  It seems that I wasn't using
the right libraries in the right order, etc.  Again, thanks.


Mark R. Craig
Internet:  la086318@zach.fit.edu
UUCP:      ...!winnie!zach!la086318