LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

implementation of stdio.h disallow the use of the identifier stderr, stdout, stdin, ...

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)
0 Kudos
Message 1 of 3
(3,374 Views)
Well, I always treat such items as reserved words and avoid trying to reuse them as something else. (All languages have reserved words - its not just a feature of C.) Can you not use eg StdErr instead? Haven't tried this one but maybe a #undefine stderr at the top of your code might work.
 
JR
Message 2 of 3
(3,368 Views)
jr_2005 wrote:
"(All languages have reserved words - its not just a feature of C.)"

i don't mind about a limited set of reserved words. that's the case for 'if', 'while', 'for' which are syntactical construct. now, if i have to consider every single identifier defined in the standard library as a reserved word, it makes a LOT of reserved words. remember COBOL and how hard it was to find a valid variable name ? about any english word was already a reserved word... that's why i like having namespace. c++ for example have the std namespace: everything defined in the standard library is part of the std namespace, so i can disambiguate between std::stderr, log_listeners::stderr, ::stderr...

here i am defining stderr as an identifier inside a structure. the structure acts like a namespace, and allows to differentiate between "stderr" as it should be defined in stdio.h and my "stderr" which is a field of a structure. 
the problem arise only because the implementation of the library uses a global #define which replaces every single instance of the word "stderr", wether or not it identifies the pointer to the standard error stream.

(now for the record, i renamed it std_error or something similar, but the problem is still here until i want to use "stderr" again)
0 Kudos
Message 3 of 3
(3,357 Views)