Hello community,
 
after unsuccessful search in the doc, the web and this mailing list I
decided to launch this question here:
 
I wrote a data logger which simply saves the address of the format
string and the arguments of a printf-like function into a buffer. A call
looks for example like this: 
 
LOG2( "Two int's: %d,%d\n", 0, 1 ); // The '2' in the macro name
indicates, that there are 2 parameters. It can handle only 'int' size
arguments.
 
This can be executed inside an interrupt without any problems, because
it is fast. The buffer is read and printed out later from a background
task.
 
Now I want rewrite it to be able to use also arguments of different size
like 'char' and 'long long' and I would like it if the code runs on many
machines without trouble (I intend to submit it to the eCos community).
Also I know now about variadic macros, which could ease the
implementation.
 
So I think I need 3 functions or macros like this:
 
        size_t  va_size( va_list ap );                          //
returns the size of the argument list - needed for buffer allocation
        void            va_save( va_list ap, char* pBuffer);    //
copies all arguments in the argument list ap into a buffer pBuffer
        va_list         va_conv( char* pBuffer );
// converts the buffer into a va_list 
        
// on a typical stack machine va_conv could be simply a cast.
 
From my current point of view I see no way to generate these thinks in
the application code. I assume, that it is possible to create them as
compiler built-ins. At least in the case of printf all needed
information is available during compile time, because the compiler could
parse the format string.
But also in all other cases I could imagine, that it is possible to
determine the needed information during compile time. 
 
Probably I did not understand the whole matter good enough. May be there
is an other way to solve this issue?
 
Thanks in advance for any comment!
 
Thomas
 
ps: Please ignore the following attachment. I am writing from my company
account and can not avoid it.

This message (including any attachments) contains confidential
and/or proprietary information intended only for the addressee.
Any unauthorized disclosure, copying, distribution or reliance on
the contents of this information is strictly prohibited and may
constitute a violation of law.  If you are not the intended
recipient, please notify the sender immediately by responding to
this e-mail, and delete the message from your system.  If you
have any questions about this e-mail please notify the sender
immediately.

Reply via email to