Complex data type
4 messages in this thread
I need help declaring a complex data type using Manx C (3.6a)
I want a data type called "BIGA " which is (as described to FF's "CDecl"):
declare BIGA as array 100 of pointer to array 4 of pointer to array 2 of
pointer to array 10 of int
CDecl gives me: (*(*(*BIGA[100])[4])[2])[10] which doesn't compile. Manx
says: (*(*(*BIGA[100])[4])[2])[10]
^ data type is too complex WARNING: too many
subscripts or dindirections on integer;
What should I do to make manx happy? Also how do I modify specified
integers in my variable BIGA? (Like: int (*(*(*BIGA[1])[1])[1])[1] = 1 ??)
Thanks Jason Freund USENET: freund@sakura.ucdavis.edu
I usually build up complicated data declarations out of typedefs.
typedef int ctype[10]; typedef ctype *btype[2]; typedef btype *atype[4];
atype *BIGA[100];
As for referencing an individual int in this mess, you can do it just
like you would expect, but normally you end up referring to the defined
types. In the main routine you think about atypes. In the functions that
you pass atypes you think about btypes, &c. If you end up setting up this
complicated a declaration and then have to reference each individual item
from every routine, you really need to do some thinking about your data
representation.
As for the original declaration, Lattice handles it just fine as is.
That's an interesting technique, but I'm not quite sure I understand your
rationale for using it… could you explain it in more depth? You're
trying to set up a multidimensional array, but what's the reason for
referencing each individual item from every routine, as you put it?
I was mainly trying to show a way of dealing with extremely complex data
types on compilers that choke on them. The array in question was proposed
by the author of the message I was replying to. As for accessing an
individual int from within this kind of mess, I've never needed to (and
find it hard to believe that anybody else would, either.) I've played
around with a program or two that may have had this complicated a data
type, but I tend to think in terms of the intermediate types.
As an example, I might have:
typedef struct {int real, imaginary;} complex;
typedef complex vector[4];
typedef vector matrix[4];
matrix foo[10];
From within the function that declares foo, I would NEVER access the
ints that base this mess. I'd hate to try to figure out how to access the
real component of the second complex number in the third vector of the
fourth matrix in foo. I just don't think that way. Like I said, if you
have a datatype this messy and you need to access the individual ints at
every point in your program, then your program needs some serious design
work.