View Single Post
  #3   Spotlight this post!  
Unread 18-02-2007, 20:50
schroedinbug schroedinbug is offline
Registered User
FRC #0443
 
Join Date: Feb 2007
Location: Denver
Posts: 3
schroedinbug is an unknown quantity at this point
Re: Variadic functions with mcc18

First, add '#include <stdarg.h>' (without quotes at the top of the user_routines.c file).

Code:
void Debug_uchar(unsigned char count,...)
{
  va_list ap; /* the list of variables - needed for variadic functions */
  unsigned char i; /* counter variable - for loop will iterate through the arguements */

  if (num_of_prog_loops == DEBUG_LOOPS)
  {
    va_start(ap, count); /* we need to initialize the arguement list */

    for (i = 0; i < count; i++)
    {
      printf("%d: %d\n", i, va_arg(ap, unsigned char);
    }

    printf("\n");

    /* num_of_prog_loops is reset at the bottom of ????? routine */
  }

  va_end(ap);
}
num_of_prog_loops is a global variable being incremented, then set to 0 after a certain number of loops