BUG: declaring structures inside functions doesn't work


#1

From IRC we got the following code sample:

// vim: ft=c

void main() {
	struct foo {
		int a, b;
	};

	struct foo bar = { 1, 2 };
	printf( "%s\n", bar.b );
}

This fails because the compiler currently doesn’t allow structures to be declared by themselves inside a function.
The following does work:

// vim: ft=c

void main() {
	struct foo {
		int a, b;
	} bar = { 1, 2 };

	printf( "%s\n", bar.b );
}

#2

I’m being told it’s allowed by C also, but can’t find anything concrete. Probably because I’m looking wrong.


#3

Yes that original code sample is legal C code, and it should have worked in Little. That is why this post is titled “BUG”.

However in the printf the format should use %d since it is printing a number.