i am trying to name a field of a struct "stderr" which is a pointer to a type i defined which allows me to perform a formatted print on the standard error.
unfortunately, "stdio.h" defines this:
#ifdef _CVI_USE_FUNCS_FOR_VARS_
extern FILE ** CVIFUNC_C _GetFilesArray(void);
#define _files (_GetFilesArray())
#else
extern FILE * _files[FOPEN_MAX];
#endif
#define stderr _files[2]
nice, now this structure:
typedef struct
{
LISTENER *stderr;
} APPLICATION_LOG_LISTENERS;
is interpreted as:
typedef struct
{
LOG_LISTENER *_files[2];
} APPLICATION_LOG_LISTENERS;
and since _CVI_USE_FUNC_FOR_VARS_ is defined to 1 by default (how do we disable it by the way ?), it is now re-interpreted as:
typedef struct
{
LOG_LISTENER *(_GetFilesArray())[2];
} APPLICATION_LOG_LISTENERS;
which is obviously not valid C and gives 2 error when compiling:
Illegal return type 'array 2 of pointer to LOG_LISTENER'
Undefined size for field 'array 2 of pointer to LOG_LISTENER function'
note that "stdio.h" was not included from my headers, so it appears to be 'automagically' included.
now, how may i use the word 'stderr' anywhere in my code ? same question for stdin, stdout, ....
(that's exactly the kind of problem which demonstrates that: C is badly defined, blind preprocessing is bad, global definitions are evil, namespace pollution cannot be avoided in C and finally use of namespace would have saved the world. i hate this language)