Click here to Skip to main content
15,395,877 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to write the macro to print my message on the uart terminal.
In my MCU series API
uart_print_user_msg((uint8_t *)"\r\n user mesage");
or
uart_print_user_msg((uint8_t *)buf);
i.e buf is char array pass to the function.
is it possible to write the macro like
#define TM_PRINTF(f_, ...) printf((f_), __VA_ARGS__)
#define TM_SNPRINTF(s_, sz_, f_, ...) snprintf((s_), (sz_), (f_), __VA_ARGS__)


declaration of the function is
void uart_print_user_msg(uint8_t *p_msg)


What I have tried:

what I tried
#define MY_PRINTF(f_, ...) uart_print_user_msg((f_), )
Posted
Updated 22-May-21 7:47am
v2
Comments
Richard MacCutchan 21-May-21 9:36am
   
What happens in each case?
Shadababe04 21-May-21 9:44am
   
Hi Richard
void uart_print_user_msg(uint8_t *p_msg) is the function which is used to print the message.I want to write the micro as I gave the example of printf function
Richard MacCutchan 21-May-21 10:26am
   
Then you should write them and find out whether they work or not. We cannot do it for you.
Rick York 21-May-21 11:30am
   
While you're at it, you might want to include the cast in the macro.

1 solution

C++
#define MY_PRINTF  uart_print_user_msg 
should do the job.

I dont like macros, because of strange errors and debugging huzzle. Avoid them, and use functions. The compiler and linker will produce the same code so the advantages arent so great as you may think.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900