Is there a vsprintf?

Post your requests and ideas on the future development of mikroC for dsPIC30/33 and PIC24.
Post Reply
Author
Message
Daniel Wee
Posts: 38
Joined: 14 Jun 2007 22:05

Is there a vsprintf?

#1 Post by Daniel Wee » 06 Nov 2007 23:32

I need to use a vsprintf function with the ellipsis but realized that mikroC doesn't seem to have a vsprintf function. Is there a way to do what vsprintf does in mikroC? Or is this a lost cause?

Daniel

p.s. va_end doesn't seem to exist either.

User avatar
srdjan
mikroElektronika team
Posts: 1552
Joined: 28 Dec 2005 12:47
Location: Serbia

Re: Is there a vsprintf?

#2 Post by srdjan » 07 Nov 2007 11:17

Hi,
Daniel Wee wrote:I need to use a vsprintf function with the ellipsis...
Well, thats the sprintf function and it exists as library routine in mikroC.

Dr Jeff
Posts: 13
Joined: 09 Dec 2007 21:39
Location: Lyme Regis, ENGLAND
Contact:

vsprintf

#3 Post by Dr Jeff » 09 Dec 2007 21:51

Drago Srdjan,

with respect it is not the same to use sprintf instead of vsprintf.

Whilst it is true sprintf provides a work around - it makes more complicated to implement overloaded forms of a printf function specific to a given application - for example I use the following function as part of a packet based messaging system - it is fully ANSI C compliant and works with many other embedded compilers.

The variable args support in C is a powerful way of creating handlers for variable data in a useful way - please add it to your list of updates for this otherwise excellent compiler.

Regards,

Jeff

Below example code using vsprintf - impossible to write using sprintf

/*=============================================*/
/* */
/* Message - Send message to external link */
/* */
/*=============================================*/
/*-------------------- Private variables -------------------------*/
SHORT_RESULT SysResultMessage;
char szMessageBuff[SHORT_BLOCK_SIZE];
void Message(BYTE byResultCode, const char *format, ... )
{
va_list ArgumentList;
WORD wCopyCount;
/*-------------------- Initialise pointers -----------------------*/
va_start (ArgumentList, format); // Variable argument begin
/*-------------------- Generate string ---------------------------*/
wCopyCount = vsprintf(szMessageBuff, format, ArgumentList);
va_end (ArgumentList); // Variable argument end
/*-------------------- Generate message --------------------------*/
SysResultMessage.byCommand = byResultCode;
SysResultMessage.wSize = wCopyCount;
if (SysResultMessage.wSize > SHORT_BLOCK_SIZE)
SysResultMessage.wSize = SHORT_BLOCK_SIZE;
SysResultMessage.Response = rcInfo;
for (wCopyCount = 0; wCopyCount < SysResultMessage.wSize; wCopyCount++)
SysResultMessage.byData[wCopyCount] = szMessageBuff[wCopyCount];
SendResult((RESULT*)&SysResultMessage);
/*----------------------------------------------------------------*/

User avatar
srdjan
mikroElektronika team
Posts: 1552
Joined: 28 Dec 2005 12:47
Location: Serbia

Re: vsprintf

#4 Post by srdjan » 10 Dec 2007 12:15

Dr Jeff wrote:Drago Srdjan,

with respect it is not the same to use sprintf instead of vsprintf.
- I never said it's the same. If you take a look at the quote in my previous post, you'll see that I have stated that "vsprintf function with the ellipsis" is sprintf. Vsprintf does not take ellipsis as its input parameter. However, it may be that I have misunderstood Daniel's request.
Dr Jeff wrote: Whilst it is true sprintf provides a work around - it makes more complicated to implement overloaded forms of a printf function specific to a given application - for example I use the following function as part of a packet based messaging system - it is fully ANSI C compliant and works with many other embedded compilers.

The variable args support in C is a powerful way of creating handlers for variable data in a useful way - please add it to your list of updates for this otherwise excellent compiler.
- Thank you for your kind words and suggestions. We'll see to implement this routine with some of the next releases. I can not give you any deadlines right now.

Dr Jeff
Posts: 13
Joined: 09 Dec 2007 21:39
Location: Lyme Regis, ENGLAND
Contact:

#5 Post by Dr Jeff » 10 Dec 2007 17:35

Hi Srdjan,

I'm sorry if I've offended - and son't want to worry about who said or typed what - the point is vsprintf is used (with the associated varargs features) to allow effective overloading of printf with our own functions - sprintf can help - but does not provide the same features.

Please add the varargs and vsprintf to the wish list - I am guessing that the varargs features require stack frame manipulation and recovery - with the little I've so far experienced with writing assembler bodies to functions I'm hoping it shouldn't be too hard.

Regards,

Jeff

User avatar
srdjan
mikroElektronika team
Posts: 1552
Joined: 28 Dec 2005 12:47
Location: Serbia

#6 Post by srdjan » 11 Dec 2007 14:06

Dr Jeff wrote:Hi Srdjan,

I'm sorry if I've offended - and son't want to worry about who said or typed what - the point is vsprintf is used (with the associated varargs features) to allow effective overloading of printf with our own functions - sprintf can help - but does not provide the same features.
- I was not offended at all. I just wanted to clear things out. And yes, you are right, sprintf does not provide the same features as vsprintf.
Dr Jeff wrote: Please add the varargs and vsprintf to the wish list - I am guessing that the varargs features require stack frame manipulation and recovery - with the little I've so far experienced with writing assembler bodies to functions I'm hoping it shouldn't be too hard.
- Note is taken. We'll see to analyze the complicity of implementation and implement implement these features as soon as possible.

Dr Jeff
Posts: 13
Joined: 09 Dec 2007 21:39
Location: Lyme Regis, ENGLAND
Contact:

#7 Post by Dr Jeff » 12 Dec 2007 10:14

Drago Srdjan,
thank you for adding to the wish list. If you need any working code examples to try this out I am more than happy to help.
Best wishes,
Jeff

Post Reply

Return to “mikroC for dsPIC30/33 and PIC24 Wish List”