Re: [EE] Saving "printf" arguments for later? Real-time on slow processor.

smplx <[email protected]>
Newsgroups gmane.comp.hardware.microcontrollers.pic
Message-ID <[email protected]>

On Mon, 20 Jan 2025, Isaac Marino Bavaresco wrote:

> Is it possible for you to replace que calls to 'printf' with calls to 
> different functions depending on the specific formatting?
>
> If so, each function would know exactly what it is receiving as 
> parameters and simplify the saving of the data.

This is a very good solution. However I would go one step further and 
write an additional preprocessor program (pre-preprocessor) that looks for 
printf and generates the sequence of specific "step" functions based on 
the format string. This would be very easy to do and would leave your 
source code "printf"s unchanged. The only issue would be if you used a 
variable format string[1] (but trapping that would be trivial). Parsing 
the source file would be trivial with the only complication being to check 
for matching parenthesis outside of string literals. Surely this would 
only take a couple of hours to do at most.

Rgards
Sergio Masci

[1]
 	char *fmt;

 	fmt = "x=%d";

 	printf(fmt, x);

or

 	printf(tst ? "start=%d\n" : "end=%\n", pos);
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.