Topic: array declarators


Author: cainen@nca.co.uk (Nick Caine)
Date: Tue, 3 May 1994 13:47:22 GMT
Raw View
I am currently creating a meta database for C++ classes and as such it has to
be able to print out the classes it knows about. This has given rise to the question

why do we declare arrays on the rhs of the var name.

eg. int var1[10];

instead of

    int[10] var1;

I have a base class
    type
with sub classes
    array_type,reference_type, pointer_type,simple_type,complex_type, typedef_type

using these I can build up ptr's to ptr's to arrays of ptr's ..... but when it comes
to print an attribute (type,name) and the attribute's an array I somehow have to get
the name in the middle of the type.

initially I thought I was getting confused between types and declarators as pointers,
references and arrays are declarators in the ARM but then how would I create complex
attributes like a pointers to pointers to arrays of pointers. Obtuse but I know
some one will want it.

confused

Nick Caine





Author: pjl@graceland.att.com (Paul J. Lucas)
Date: Wed, 4 May 1994 14:40:22 GMT
Raw View
In <Cp8BMz.6H4@nca.co.uk> cainen@nca.co.uk (Nick Caine) writes:

>I am currently creating a meta database for C++ classes and as such it
>has to be able to print out the classes it knows about. This has given
>rise to the question

>why do we declare arrays on the rhs of the var name.

>eg. int var1[10];

>instead of

>    int[10] var1;

 Because that's the way Thompson/Ritchie defined it to be.
 The rationale, if you were to read K&R, is that declarations
 should mirror their use.  Since a[i] is used as such, the
 declaration should match: int a[10];

>I have a base class
>    type
>with sub classes
>    array_type,reference_type, pointer_type,simple_type,complex_type,
>    typedef_type

>using these I can build up ptr's to ptr's to arrays of ptr's ..... but
>when it comes to print an attribute (type,name) and the attribute's an
>array I somehow have to get the name in the middle of the type.

 Well, it's certainly possible; cdecl does it.  The source code
 is out on the net and you're free to obtain it.
--
 - Paul J. Lucas
   AT&T Bell Laboratories
   Naperville, IL