|
|
View previous topic :: View next topic |
Author |
Message |
kender
Joined: 09 Aug 2004 Posts: 768 Location: Silicon Valley
|
Passing a variable argument list to printf() |
Posted: Wed Sep 10, 2008 9:02 pm |
|
|
Collagues,
I’d like to write a function that uses the formatting power of printf() and does initialization and termination of the communication channel. Unfortunately, I’m unable to pass a variable argument list to printf.
Code: | #device PASS_STRINGS=IN_RAM
void my_printf(char pFormat[], ...)
{
// initialize the channel
printf(my_putc, pFormat, _VA_LIST);
// terminate the channel
} |
Test bed:
Code: | my_printf("\n\r**%d", 7); |
This code compiles (PCWH 4.071), but instead of sending **7, it sends **%d. Am I making wrong assumptions about variable argument lists?
Cheers,
- Nick _________________ Read the label, before opening a can of worms. |
|
|
Ttelmah Guest
|
|
Posted: Thu Sep 11, 2008 2:50 am |
|
|
Unfortunately...
The problem is that space in the PIC is limited. The full implementation of all possible features in a printf command, would take more space, than most PIC's have. Hence the printf command is implemented, as a 'compile only what is needed' form. This keeps it from being too large, but means it cannot be used (directly) with variable argument lists.
You can operate it with a variable argument list, by 'encapsulating' it. So you write your own 'wrapper' function, setup to accept the particular options you want, and call this, which then parses the string, works out which version of printf is needed, and uses this. The result will be large, if you have any significant number of different printf layouts. There is a version implementing a simplified form of this, in the code library, dating from before any form of variable arguments were supported by CCS.
Best Wishes |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|