I have a piece of code I'd like to make Arduino editor friendly. The code is written in C and contains macros the Arduino IDE can't deal with. Is it a good idea to turn those macros into functions?
#define AN221_EXECUTE_Low cbi(PORTA, PIN0) //drive EXECUTE low
#define AN221_PORb_High sbi(PORTA, PIN1) //drive PORb high
#define AN221_ACTIVATE bit_is_set(PINA, PIN2) //sense ACTIVATE high
#define AN221_NO_ERROR bit_is_set(PINA, PIN3) //sense ERRb high i.e. no rror
#define AN221_ERRb_Input outp(0xEB, DDRA) //make uP drive ERRb
#define AN221_ERRb_Output outp(0xE3, DDRA) //make uP sense ERRb
asked Mar 11, 2017 at 14:14
-
Compiled ok for me - what were you expecting and what actually happened?JRobert– JRobert2017年03月11日 22:04:32 +00:00Commented Mar 11, 2017 at 22:04
1 Answer 1
Is it a good idea to turn those macros into functions?
it depends.
macros are fast, but lack type checking.
functions offer type checking but incur overhead.
whether one is better than the other depends on your priorities.
answered Mar 11, 2017 at 15:26
lang-c