Skip to main content
matt-crc
Senior III
February 22, 2025
Solved

can't get standard c-function/macro (va_list, va_start, va_end) to work properly. compiler bug?

  • February 22, 2025
  • 2 replies
  • 886 views

Hello,

The following code compiles, but doesn't give the me results I'm expecting:

 

 

void syslog2(uint8_t pri, const char *fmt, ...) {
	va_list args;
	va_start(args, fmt);
	printf(fmt, args);
	va_end(args);
}
main() {
 printf("%s\r\n", _tx_version_id);
 syslog2(SYSLOG_INFO, "Azure RTOS - %s\r\n", "test" /*_tx_version_id*/);
}

 

 

 this is the output:

mattcrc_0-1740191974871.png

what am I missing?

thanks

Matthew

 

This topic has been closed for replies.
Best answer by AA1

This is a C question and not a ST microcontrollers question. With va_list arguments, you should use vprintf. See https://cplusplus.com/reference/cstdio/vprintf/

 

2 replies

AA1
AA1Best answer
Senior III
February 22, 2025

This is a C question and not a ST microcontrollers question. With va_list arguments, you should use vprintf. See https://cplusplus.com/reference/cstdio/vprintf/

 

matt-crc
matt-crcAuthor
Senior III
February 22, 2025

Hi @AA1 

Where were you 2 hours ago??  LOL

I ended up writing my own macro to get around this issue:

 

#define _LOG_FORMAT_STD(letter, format) "%s" format "\r\n", SysLog_prefix( letter )

#define _LOG_FORMAT(letter, format) \
 "%s [%s:%u] %s(): " format "\r\n", SysLog_prefix( letter ), GetFileName( __FILE__), __LINE__, __FUNCTION__


#define syslog(level, format, ...) \
	if (level == SYSLOG_FATAL) {			 \
 printf(_LOG_FORMAT(level, format), ##__VA_ARGS__); \
	} else if (level <= syslog_level) \
 printf(_LOG_FORMAT_STD(level, format), ##__VA_ARGS__)

 

But I did test your suggestion (vprintf), and it works as well.

thanks

Matthew