// filename:c2011-6-7-8-ex.c
// original examples and/or notes:
// 		(c) ISO/IEC JTC1 SC22 WG14 N1570, April 12, 2011
// http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf
// 			C2011 6.7.8 Type definitions
// compile and output mechanism:
// 		(c) Ogawa Kiyoshi, kaizen@gifu-u.ac.jp, December.xx, 2013
// compile errors and/or wornings:
// 1	(c) Apple LLVM version 4.2 (clang-425.0.27) (based on LLVM 3.2svn)
// 			Target: x86_64-apple-darwin11.4.2 //Thread model: posix
// 		(c) LLVM 2003-2009 University of Illinois at Urbana-Champaign.
// 2    gcc-4.9 (GCC) 4.9.0 20131229 (experimental)
//      Copyright (C) 2013 Free Software Foundation, Inc.
#include <stdio.h>
void * example(int i){ return (void *) i;};

// Example 1
typedef int MILES, KLICKSP();
typedef struct { double hi, lo; } range;
MILES distance;
extern KLICKSP *metricp;
range x;
range z, *zp;
int example_print1(void){
return printf("%f, %f,%f \n", x.hi, z.lo, zp->hi);
}

// Example 2
typedef struct s1 { int x; } t1, *tp1;
typedef struct s2 { int x; } t2, *tp2;
// Example 3
typedef signed int t;
typedef int plain;
struct tag {
unsigned t:4;
const t:5;
plain r:5;
};
t f(t (t));
long tt; // exchange below
long t3; //**
//c2011-6-7-8-ex.c:32:6: error: redefinition of 't' as different kind of symbol
//long t;
//     ^
//c2011-6-7-8-ex.c:24:20: note: previous definition is here
//typedef signed int t;
//                   ^
plain ip;
int example_print2(void){
return printf("%ld, %d, %ld \n", t3, ip, tt);
}

// Example 4
typedef void fv(int), (*pfv)(int);
void (*signal(int, void (*)(int)))(int);
fv *signal(int, fv *);
pfv signal(int, pfv);
int example_print3(void){
return printf("%d \n", (int) signal(1, example(2)));
}

// Example 5
void copyt(int n)
{
typedef int B[n]; // B is n ints, n evaluated now
n += 1;
B a; // ais n ints, n without += 1
int b[n]; // a and b are different sizes
for (int i = 1; i < n; i++)
a[i-1] = b[i];printf("%d, %d \n", a[1], b[1]);
}
int main(void)
{
example_print1();
example_print2();
example_print3();
copyt(3);
return printf("6.7.8 Type definitions %ld \n",tt);	
}
// 1. warning LLVM3.2
//c2011-6-7-8-ex.c:15:31: warning: cast to 'void *' from smaller integer type 'int' [-Wint-to-void-pointer-cast]
//void * example(int i){ return (void *) i;};
//                              ^
//
// 2. warning GCC4.9
//c2011-6-7-8-ex.c:15:31: warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]
// void * example(int i){ return (void *) i;};
//                               ^
//c2011-6-7-8-ex.c: In function 'example_print3':
//c2011-6-7-8-ex.c:59:24: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast]
// return printf("%d \n", (int) signal(1, example(2)));
//                        ^
//
// 3. befor add call functions annd printfs, output may be
//6.7.8 Type definitions 0 
// 4. after add call functions and printfs, outpu
// Segmentation fault: 11