Search code examples
ciar

IAR Embedded Workbench: stdarg.h isn't preprocessed


I'm building a c-language application, using IAR Embedded Workbench for ARM 7.40.
I'm using libclang to get an AST (abstract syntax tree) representation of my c-code. For that, I'm preprocessing my source-code.
The problem is with #include <stdarg.h> - it doesn't get expanded.

Original code snippet:

int before_stdarg = 1;
#include <stdarg.h>
int after_stdarg = 2;
va_list args;
#include "func1.h"
...

Preprocessed code snippet:

#line 1 "source\\App\\func1.c"
int before_stdarg = 1;
#include <stdarg.h>
int after_stdarg = 2;
va_list args;
#line 1 "C:\\testAppC\\source\\App\\func1.h"
...

Viewing stdarg.h:

#ifdef __ICCARM__
#error "Reading built-in header-file. If you used upper case, try #include <stdarg.h>"
#endif

A second issue: where is va_list defined?
commenting out #include <stdarg.h> results in a compilation error: Error[Pe020]: identifier "va_list" is undefined

What am I missing?

Update, due to comments:
The Q is not for IAR EWARM newbies, as the marked answer can hint.
The issue occurs on any minimal hello-world example, simply by adding the #include <stdarg.h>, without even using it!
The preprocess command is a copy-paste of the regular build command, with the --preprocess=l PATH_TO_PREPROCESSED_OUTPUT_FILE addition:

PS C:\testAppC> iccarm.exe source\App\func1.c -DSTM32L476xx -DUSE_HAL_DRIVER -I"C:\Program Files (x86)\IAR Systems\Embedded Workbench 7.2\arm\CMSIS\Include" -I"C:\Program Files (x86)\IAR Systems\Embedded Workbench 7.2\arm\inc\c" -I"source\App" -I"source\Device" --char_is_signed --cpu=Cortex-M4 --debug --dlib_config  "C:\Program Files (x86)\IAR Systems\Embedded Workbench 7.2\arm\INC\c\DLib_Config_Normal.h" --endian=little --fpu=None --no_clustering --no_code_motion --no_cse --no_inline --no_scheduling --no_tbaa --no_unroll -On -e -o testAppC\Obj --preprocess=l C:\testAppC\.aurora\tmp\func1.c.i

Solution

  • In iccarm 7.40 the stdarg.h in the filesystem is only a stub file. The varargs machinery is built into the compiler and activated by the #include <stdarg.h> directive. This is also why this include directive is not expanded when using the --preprocess command line option. This was changed recently and as of iccarm 8.40 the compiler uses the stdarg.h from the file system.