Re: [cc65] Interrupt handlers in C as part of the C library ?

From: Spiro Trikaliotis <ml-cc651trikaliotis.net>
Date: 2012-01-21 14:00:25
Hello Oliver,

* On Sat, Jan 21, 2012 at 01:40:44PM +0100 Oliver Schmidt wrote:
 
 
> /* Possible returns for irq_handler() */
> #define IRQ_NOT_HANDLED	0
> #define IRQ_HANDLED	1

W/o having looked at the code: Why are the above returns needed?

> typedef unsigned (*irq_handler) (void);

Bad style, I would highly advise to use the "int".

You never worked with some more or less official coding guideline, did
you? ;)


> void __fastcall__ set_irq (irq_handler f, void *stack_addr, size_t stack_size);

Just personal style:

Instead of defining irq_handler as a type which is a pointer to a
function, I would define irq_handler as a type which is the function.
That way, the above two lines would look like:

typedef unsigned int irq_handler(void);
void __fastcall__ set_irq (irq_handler * f, void *stack_addr, size_t stack_size);

Here, it is explicit that f is a pointer to something.


Another neat side-effect:

Now, you can write your irqhandler as:

        irq_handler myirqhandler;

        unsigned int myirqhandler(void)
        {...}

and the compiler will check at the point of declaration of the function
(first line) that the declaration of the function is the same as the
declaration of the type. AFAIK, this is not possible if irq_handler is
defined as a pointer to a function.

Regards,
Spiro.

-- 
Spiro R. Trikaliotis                              http://opencbm.sf.net/
http://www.trikaliotis.net/                      http://vice-emu.sf.net/
----------------------------------------------------------------------
To unsubscribe from the list send mail to majordomo@musoftware.de with
the string "unsubscribe cc65" in the body(!) of the mail.
Received on Sat Jan 21 14:00:53 2012

This archive was generated by hypermail 2.1.8 : 2012-01-21 14:00:56 CET