CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Passing a variable argument list to printf()

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

Passing a variable argument list to printf()
PostPosted: Wed Sep 10, 2008 9:02 pm     Reply with quote

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







PostPosted: Thu Sep 11, 2008 2:50 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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