arrays -> pointers
Kevin Rushforth
rushfort at esunix.UUCP
Wed Jan 20 03:56:33 AEST 1988
in article <3761 at sigi.Colorado.EDU>, swarbric at tramp.Colorado.EDU (SWARBRICK FRANCIS JOHN) says:
>
> Here is a line of code that I got out of a book:
>
> (*(mn+hsel-1)->func[vsel-1])(hsel,vsel);
Correct, assuming the following typedefs and variables (or some equivalent):
typedef void (*funcp)();
typedef struct
{
funcp *func;
} mystruct;
mystruct *mn;
int vsel,hsel;
> With it using arrays in both places that would look normal I think it would
> look like this:
>
> (*ms[hsel-1].func[vsel-1])(hsel,vsel);
Also, correct;
> ANyway, does anyone know how to get it to that it won't use *any* array
> brackets? I tried stuff like:
>
> (*(*(mn+hsel-1)->func+vsel-1))(hsel,vsel);
Not quite. This should be written as:
(**((mn+hsel-1)->func+vsel-1))(hsel,vsel);
In your example, you try to add (vsel-1) to the pointer (mn+hsel-1)->func
AFTER dereferencing it rather than before. Hope this helps.
--
Kevin C. Rushforth
Evans & Sutherland Computer Corporation
UUCP Address: {ihnp4,ucbvax,decvax,allegra}!decwrl!esunix!rushfort
Alternate: {bellcore,cbosgd,ulysses}!utah-cs!esunix!rushfort
More information about the Comp.lang.c
mailing list