Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Found something cool in C11

Name: Anonymous 2014-08-06 10:58

c.h
typedef int i;
extern int shi;


c.c
#include "c.h"
#include "c.h"
#include "c.h"

int shi;

int
main (void)
{
return 0;
}


As you can see C11 allows multiple typedefs of the same type to the same type, a typedef long i; would be illegal
This avoids the need for include guards but sadly it does not work for structs, not that this is a problem

Name: Anonymous 2014-08-06 16:30

>>10
Ok I'm a bit confused now: in gcc when you specify the standard to C90 you get no warnings nor errors BUT in clang it says that that is a C11-only feature. I'm still not convinced as (quoting from the ISO C90) "a typedef name shares the same name space as other identifiers declared in ordinary declarators", so I interpret this implies that a typedef name also shares the same rules for redeclaration of object in the file scope (6.7.2).
Check out this:
typedef int a;
main(){
typedef char a;
return 0;
}

This is ok even with clang. It's not the same thing but it shows how a typedef name identifier is similar to an object identifier.

Maybe the new addition in C11 6.7.3 is just a clarification.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List