Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

farmerdoug

macrumors 6502a
Original poster
Sep 16, 2008
541
0
if maxes is a ** to a struct and sys is a * to the same type of struct
can I do this

maxes[][] = sys[]?

The answer seems to be yes because I tested it but I not sure why. Haven't I violated some pointer rule?

thanks
 

mfram

Contributor
Jan 23, 2010
1,307
343
San Diego, CA USA
You've posted theoretical code which won't compile. Post a real example and maybe we can answer. Keep in mind that you can assign pointers around all you want. But the compiler will not copy entire arrays using an assignment statement.
 

Sydde

macrumors 68030
Aug 17, 2009
2,552
7,050
IOKWARDI
if maxes is a ** to a struct and sys is a * to the same type of struct
can I do this

maxes[][] = sys[]?

The answer seems to be yes because I tested it but I not sure why. Haven't I violated some pointer rule?

thanks

Not really. The basic rule in C is that a pointer implicitly points to an array of its type. A pointer to a pointer implicitly points to an array of pointers, and each pointer in that array implicitly points to an array of the declared type, so using the doubled subscript notation is perfectly valid.

Note that a function pointer is one pointer type you should obviously never treat as a pointer to an array.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.