Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Variadic functions with mcc18 (http://www.chiefdelphi.com/forums/showthread.php?t=54473)

schroedinbug 18-02-2007 17:12

Variadic functions with mcc18
 
Has anyone used variadic functions in their FRC code? I want to have a variadic debugging function, but the function appears to get ignored when called. I know the stdarg.h is available and the code compiles, bug I get zero output from the function call (it should do a varying number of printf's, including some for general newlines, which it does not do).

Any thoughts/opinions?

If you need to see code, I can probably get a small example of what I want posted.

jesusescobar 18-02-2007 17:14

Re: Variadic functions with mcc18
 
example would help:D

schroedinbug 18-02-2007 20:50

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

Alan Anderson 18-02-2007 23:26

Re: Variadic functions with mcc18
 
Your printfs will compile but will fail to work if you don't #include <stdio.h>.

schroedinbug 19-02-2007 00:51

Re: Variadic functions with mcc18
 
Quote:

Originally Posted by Alan Anderson (Post 581288)
Your printfs will compile but will fail to work if you don't #include <stdio.h>.

This is in the user_routines.c file, which does have that defined. I'd expect the printf calls to work, since I've used them outside the function in the same source file. It seems that the program doesn't even go into the variadic function.


All times are GMT -5. The time now is 04:50.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi