This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

va_list trouble

hi all,


i've written this custom printf function,
but it don't work if i pass arguments, i get undefined chars as output.

//-------------------------------------------------------------------------------------------------
int _vmprintf(const unsigned char * msg, ...)
{
int ret_val;
va_list ap;

va_start(ap, msg);
ret_val=sprintf(spbuff, msg, ap);
va_end(ap);
_vmWrite(vm_stdio, ret_val, spbuff);

return ret_val;
}


If any halp, thanks, angelo

Parents
  • [First, a note: this is a generic C issue that has no particular relevance to Keil or 8051 programming. You should have asked this elsewhere, e.g. in the C FAQ.]

    You're apparently under the impression that a variable argument list (expressed as "...") is the same thing as a va_list passed as a single argument. Well, guess what? It isn't.

    Break out your C textbook (or the C51 docs if you must) and look up the C Standard Library function vsprintf(). Also re-check what the textbook has to say about the tools offered by <stdarg.h> and how to use them.

    [And please, in the future, try to Please read the manual before asking such basic questions. Believe it or not, all those sheets of dead tree covered in ink did accompany your Keil CD for a good reason!]

Reply
  • [First, a note: this is a generic C issue that has no particular relevance to Keil or 8051 programming. You should have asked this elsewhere, e.g. in the C FAQ.]

    You're apparently under the impression that a variable argument list (expressed as "...") is the same thing as a va_list passed as a single argument. Well, guess what? It isn't.

    Break out your C textbook (or the C51 docs if you must) and look up the C Standard Library function vsprintf(). Also re-check what the textbook has to say about the tools offered by <stdarg.h> and how to use them.

    [And please, in the future, try to Please read the manual before asking such basic questions. Believe it or not, all those sheets of dead tree covered in ink did accompany your Keil CD for a good reason!]

Children