[OCLUG-devel] declaring structures outside of main()

James Colannino james at colannino.org
Sat Jun 19 18:19:47 PDT 2004


This is really weird and I was hoping that someone could shed some light 
on this.  The following code will be condensed from its original version 
for clarity.  Anyway, I have the following:

#include <stdio.h>

const int MAX_COUNT = 6;

struct type {
	[...variables...]
};

struct type variable_name[MAX_COUNT];

int main()

{
	[...]
	return 0;
}

When I do this, I get the following error from gcc:

error: variable-size type declared outside of any function

However, when I try struct type variable[x] (x is any number) instead of 
struct type variable[MAX_COUNT], it compiles successfully.  I want this 
to be a global structure.  I have no idea what's going on :(  Anyone 
know?  I know that it has to be something I'm doing, but it seems weird 
that I can declare it with an explicit number outside of any function 
but not when I'm using a constant.

James
-- 
My blog: http://www.crazydrclaw.com/
My homepage: http://james.colannino.org/

"There are no uninteresting things; only uninterested people." --G.K. 
Chesterton



More information about the OCLUG-devel mailing list