NO

Author Topic: wchar.h bug  (Read 2902 times)

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
wchar.h bug
« on: July 22, 2018, 06:50:52 PM »
In the header "wchar.h" there is a wrong definition of FILE, defining it only in the structures namespace:
Code: [Select]
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.
Code: [Select]
#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.
Code: [Select]
typedef struct FILE FILE;
« Last Edit: July 22, 2018, 06:53:00 PM by frankie »
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
Re: wchar.h bug
« Reply #1 on: July 23, 2018, 06:19:29 PM »
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

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: wchar.h bug
« Reply #2 on: July 24, 2018, 12:07:09 PM »
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

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 2266
    • http://www.smorgasbordet.com
Re: wchar.h bug
« Reply #3 on: July 24, 2018, 03:54:42 PM »
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

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
Re: wchar.h bug
« Reply #4 on: July 25, 2018, 11:34:24 AM »
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:
Quote
If 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:
Quote
If 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