arrays of structs

Discussion in 'Mac Programming' started by farmerdoug, Feb 6, 2013.

  1. macrumors 6502a

    Joined:
    Sep 16, 2008
    #1
    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
     
  2. macrumors 6502a

    Joined:
    Jan 23, 2010
    Location:
    San Diego, CA USA
    #2
    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.
     
  3. thread starter macrumors 6502a

    Joined:
    Sep 16, 2008
    #3
    It does compile.
    Anyway I've stop using that code.
    Thanks
     
  4. macrumors 68000

    Sydde

    Joined:
    Aug 17, 2009
    #4
    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.
     

Share This Page