News:

Download Pelles C here: http://www.smorgasbordet.com/pellesc/

Main Menu

wchar.h bug

Started by frankie, July 22, 2018, 06:50:52 PM

Previous topic - Next topic

frankie

In the header "wchar.h" there is a wrong definition of FILE, defining it only in the structures namespace:
struct FILE;
When using the library extension 2, defining __STDC_WANT_LIB_EXT2__ , the compiler complains on the extended functions definitions.
The error doesn't appear if the inclusion of wchar.c follows stdio.h, because the latter includes a correct definition for FILE structure.
I.e. the following code will fail.

#define __STDC_WANT_LIB_EXT2__ 1
#include <wchar.h> //Move declaration after stdio.h inclusion to make it compile
#include <stdio.h>

int main(void)
{
printf("<wchar.h> Bug V9.00\n");
}

To fix replace the wchar.h line above with the following that correctly define FILE structure at global namespace.

typedef struct FILE FILE;
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

Pelle

I think a better idea is to add the keyword struct before FILE in the block guarded by __STDC_WANT_LIB_EXT2__ - like in other places of wchar.h.
Should be fixed now.
/Pelle

frankie

Of course it's the same.  :)
I was using the typedef definition from <stdio.h>, where you declare the complete FILE structure in global and structures namespaces.
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

Pelle

It's not the same, which was the whole point. Try compiling your solution and example in C99 mode without extensions enabled.
Anyway, case fixed and closed.
/Pelle

frankie

Sorry, you're right (as always more or less  :D).
I forget that duplication of identical typedef's is specific of C11, as per ISO/IEC 9899:2011 §6.7/3 Declarations:
QuoteIf an identifier has no linkage, there shall be no more than one declaration of the identifier (in a declarator or type specifier) with the same scope and in the same name space, except that a typedef name can be redefined to denote the same type as it currently does and tags may be redeclared as specified in 6.7.2.3.

For completeness the C99 standard miss the last sentence:
QuoteIf an identifier has no linkage, there shall be no more than one declaration of the identifier (in a declarator or type specifier) with the same scope and in the same name space, except for tags as specified in 6.7.2.3.
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide