// filename:c2011-6-7-6-2-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.6.2 Array declarators
// 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.
#define C2011_6_7_6_2_EX
// compile cc c2011-6-7-6-2-ex.c c2011-ex.c 
#include "c2011-ex.h"
#include <stdio.h>
// Example 1
float fa[11], *afp[17];
// Example 2
extern int *x;
extern int y[];
// Example 3
extern int n;
extern int m;
void fcompat(void)
{
int a[n][6][m];
int (*p)[4][n+1];
int c[n][n][6][m];
int (*r)[n][n][n+1];
p = a; // invalid: not compatible because4 != 6
r = c; // compatible, but defined behavior only if
	// n == 6 andm == n+1
	printf("p= %d r=%d ", *p[0][0],*r[0][0][0]);
}
// Example 4
extern int n;
//** int A[n]; // invalid: file scope VLA **//
//c2011-6-7-6-2-ex.c:32:5: error: variable length array declaration not allowed at file scope
//int A[n]; // invalid: file scope VLA
//    ^ ~

//** extern int (*p2)[n]; // invalid: file scope VM **//
//c2011-6-7-6-2-ex.c:33:14: error: variably modified type declaration not allowed at file scope
//extern int (*p2)[n]; // invalid: file scope VM
//			   ^

int B[100]; // valid: file scope but not VM
void fvla(int m, int C[m][m]); // valid: VLA with prototype scope
void fvla(int m, int C[m][m]) // valid: adjusted to auto pointer to VLA
{
typedef int VLA[m][m]; // valid: block scope typedef VLA
struct tag {
int (*y)[n]; // invalid: y not ordinary identifier **//// if LLVM3.2 please comment this line
// c2011-6-7-6-2-ex.c:40:7: error: fields must have a constant size: 'variable length array in structure' extension will never be supported(LLVM3.2)
//int (*y)[n]; // invalid: y not ordinary identifier
//		^
// GCC4.9 no error
int z[n]; // invalid: z not ordinary identifier **//// if LLVM3.2 please comment this line
// c2011-6-7-6-2-ex.c:41:5: error: fields must have a constant size: 'variable length array in structure' extension will never be supported(LLVM3.2)
//int z[n]; // invalid: z not ordinary identifier
//    ^
// GCC4.9 no error
	}tag1;
printf("%d %d \n",tag1.y[0],tag1.z[0]); // if LLVM3.2 please comment this line
int D[m]; // valid: auto VLA
//** static int E[m]; // invalid: static block scope VLA **//
// 1. c2011-6-7-6-2-ex.c:44:12: error: variable length array declaration can not have 'static' storage duration( LLVM3.2)
//static int E[m]; // invalid: static block scope VLA
//           ^ ~
// 2. c2011-6-7-6-2-ex.c:64:12: error: storage size of 'E' isn't constant ( GCC4.9)
// extern int F[m]; // invalid: F has linkage and is VLA **//
// 1. c2011-6-7-6-2-ex.c:45:12: error: variable length array declaration can not have 'extern' linkage(LLVM3.2)
//extern int F[m]; // invalid: F has linkage and is VLA
//	^ ~
// 2. c2011-6-7-6-2-ex.c:69:13: error: object with variably modified type must have no linkage	(GCC4.9)
int (*s)[m]; // valid: auto pointer to VLA
// extern int (*r)[m]; // invalid: r has linkage and points to VLA **//
// 1. c2011-6-7-6-2-ex.c:47:14: error: variably modified type declaration can not have 'extern' linkage(LLVM3.2)
//extern int (*r)[m]; // invalid: r has linkage and points to VLA
//             ^
// 2. c2011-6-7-6-2-ex.c:75:15: error: object with variably modified type must have no linkage(GCC4.9)
static int (*q)[m] = &B; // valid: q is a static block pointer to VLA
}
int main(void)
{
	int C[2][2];
	fvla(2, C);
	fcompat();
return printf("6.7.6.2 Array declarators %d %d %d\n",n,m,B[0]);
}
// 1.output LLVM3.2 may be
//p= 1522596552 r=1522596552 6.7.6.2 Array declarators 0 0 0
// 2.output GCC4.9
// 0 0 
// p= 0 r=0 6.7.6.2 Array declarators 0 0 0