Re: [cc65] Possible bug?

From: Adam Dunkels <>
Date: 2004-06-09 23:29:04
On Wed, 2004-06-09 at 21:48, Shawn Jefferson wrote: 
> I don't know if this would be a bug or not, but if I
> have the following code:
> #define disable_irq(n)        \
>   asm("lda #$80");            \
>   asm("trb $fd01+"#n"*4") 

It isn't a bug: this is the way C works and hasn't got anything to do
with the fact that the macro contains in-line assembler. The macro will
be expanded and the resulting code will look like this:

    asm("lda #$80");

asm("trb $fd01+"#n"*4");

Note that the last asm() statement will be executed regardless of the
value of JOYSTICK.

Define the macro like this instead:

#define disable_irq(n) do { \
   asm("lda #$80"); \
   asm("trb $fd01 + "#n"*4"); \
} while(0)

Then the macro will behave just like a one-line C statement and the if()
statement will work. The do{}while(0) code will be optimized away so it
will not produce any larger code.



Adam Dunkels <>

To unsubscribe from the list send mail to with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Wed Jun 9 23:29:11 2004

This archive was generated by hypermail 2.1.8 : 2004-06-09 23:29:19 CEST