tags:

views:

99

answers:

2

Is it possible to have the array subscript before the variable name in declaration?

For example, is it possible to have

char [10]data;

where the intended declaration is:

char data[10];

I know that this might be stretching it a bit too much, but I have the variable type defined using #define, which I need to change from int to char[10] type.

So, could I just use #define TYPE char[10] instead of #define TYPE int? Or is there a better way to achieve this?

Edit:

Must I use 2 different #define statements like this?

#define TYPE char
#define SIZE [10]

and then use:

TYPE data SIZE;
+11  A: 

You might want to consider using a typedef for this:

typedef char TYPE[10];
mipadi
I think the OP wants `data` to be the name of his variable; maybe change it to `TYPE` here to match the question?
Carl Norum
+1 Just to complement mipadi's answer ... and then define your object with `TYPE data;` meaning `data` is an array of 10 char.
pmg
@Carl Norum: Good point, fixed that.
mipadi
...and if you need it to be a macro, then `typedef char char10[10];` followed by `#define TYPE char10`
caf
+2  A: 

Try:

typedef char TYPE[10];
Fabian