Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4921

SDK • Re: troubletrouble defining a macro to replace a zero argument fn call: micros()

$
0
0
Not necessarily relevant here, but nowadays I often use inline functions to achieve the same effect as a macro with much less fighting over the syntax.
Getting this thread back on topic , I'm trying to use a macro to use Serial.printf or Serial2.printf and again it's a pain in the whole with crazy macro systax issues. I already gave up macro concatenation and did it long hand.

Code:

    #define SERIAL_PORT      // null,1,2: IDE Wire.Serial goes to USB    #define UART M_CONC(Serial,SERIAL_PORT)     //  abandon macro fuckery, too long.     #if (SERIAL_PORT+1-1 ==0)       #define DEBUG_PRINTF "Serial.printf"      #elif (SERIAL_PORT+1-1 ==1)      #define DEBUG_PRINTF "Serial1.printf"       #else // 2      #define DEBUG_PRINTF "Serial2.printf"    #endif

However, this still fails to compile when I use DEBUG_PRINTF :

Code:

 error: expression cannot be used as a function  784 |     DEBUG_PRINTF("# system clock = %d MHz\n",clock_get_hz(clk_sys)/(1000*1000));
Well , I thought the macro substitution happened in the preprocessor, so that is before it gets to interpret the text as a fn call. Whatever.

Can you suggest how I get a generalised DEBUG_PRINTF function call using inline fns?

TIA.

Statistics: Posted by pie_face — Fri Nov 22, 2024 10:10 am



Viewing all articles
Browse latest Browse all 4921

Trending Articles