Passing va_list as a function argument Topic is solved

Technical questions regarding the XTC tools and programming with XMOS.
jmarple
Junior Member
Posts: 5
Joined: Tue Jun 14, 2016 5:09 am
Location: MA, USA

Passing va_list as a function argument

Post by jmarple »

Hello everyone,

I have the following code which is trying to accept va_list as an argument:

foo.c:

Code: Select all

#include "foo.h"

void foo(va_list arg)
{
  // .. stuff here
}
foo.h:

Code: Select all

#include <stdarg.h>

void foo(va_list arg);
I get the following error when I build on xTimeComposer 14.20 on Ubuntu 15.10 64-bit
foo.h:##:##: error: parse error before "va_list"
When I declare the function prototype in the c file, it compiles fine. The error only occurs when I add the function prototype to the header file. Am I missing something really obvious here? Or perhaps a bug? Thanks in advanced.


View Solution
User avatar
ers35
Active Member
Posts: 62
Joined: Mon Jun 10, 2013 2:14 pm

Post by ers35 »

I tried your exact code and it compiles without error with xTimeComposer 14.2.0 on Ubuntu 16.04.

Code: Select all

// foo.h
#include <stdarg.h>

void foo(va_list arg);

Code: Select all

// foo.c
// xcc -c -target=XCORE-200-EXPLORER foo.c

#include "foo.h"

void foo(va_list arg)
{
  // .. stuff here
}
Are you using the xTimeComposer GUI to compile? What happens if you use the command line as in the code above?
jmarple
Junior Member
Posts: 5
Joined: Tue Jun 14, 2016 5:09 am
Location: MA, USA

Post by jmarple »

I appreciate the fast response. I am using the GUI and when I ran your command, sure enough no compiler errors.

After some experimentation, I added a main method to an xc file:

foo.xc

Code: Select all

#include "foo.h"

int main()
{
  return 0;
}
And I run the following command.
xcc -c -target=XCORE-200-EXPLORER foo.xc -o foo.xe
I get the error listed below.
./foo.h:7:10: error: parse error before "va_list"
void foo(va_list arg);
Can that be replicated? Thanks in advanced.

EDIT: I did add header guards to foo.h but that shouldn't make a difference for this example.
User avatar
ers35
Active Member
Posts: 62
Joined: Mon Jun 10, 2013 2:14 pm

Post by ers35 »

XC is not 100% compatible with C syntax. Include stdio.h and use __VALIST instead.

Code: Select all

// xcc -c stdarg2.xc

#include <stdarg.h>
// #define __VALIST char*
#include <stdio.h>

void foo(__VALIST arg);
jmarple
Junior Member
Posts: 5
Joined: Tue Jun 14, 2016 5:09 am
Location: MA, USA

Post by jmarple »

Tricky! Got it working now, thanks for the help. Do you happen to know if these small differences between C and XC are documented anywhere?
User avatar
ers35
Active Member
Posts: 62
Joined: Mon Jun 10, 2013 2:14 pm

Post by ers35 »

I am not aware of a comprehensive document that covers all the differences. The XC 1.0 specification is still useful despite missing newer additions. The XMOS Programming Guide is more up to date.