Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Feb 6, 2013, 04:47 PM   #1
farmerdoug
macrumors 6502a
 
Join Date: Sep 2008
arrays of structs

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
farmerdoug is offline   0 Reply With Quote
Old Feb 6, 2013, 07:04 PM   #2
mfram
macrumors 6502a
 
Join Date: Jan 2010
Location: 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.
mfram is offline   0 Reply With Quote
Old Feb 6, 2013, 07:44 PM   #3
farmerdoug
Thread Starter
macrumors 6502a
 
Join Date: Sep 2008
It does compile.
Anyway I've stop using that code.
Thanks
farmerdoug is offline   0 Reply With Quote
Old Feb 7, 2013, 01:47 PM   #4
Sydde
macrumors 68000
 
Sydde's Avatar
 
Join Date: Aug 2009
Quote:
Originally Posted by farmerdoug View Post
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.
__________________
You got to be a spirit. You can't be no ghost.
Sydde is online now   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
arrays? subview or submenu? tacotester1 iPhone/iPad Programming 6 Mar 14, 2014 08:06 PM
Please Help with arrays Bigred101 Mac Programming 7 Mar 13, 2014 07:39 PM
Structs and Functions or Classes and Methods? ArtOfWarfare iPhone/iPad Programming 6 Mar 21, 2013 08:27 PM
Structs and Enum problems nashyo iPhone/iPad Programming 5 Sep 9, 2012 01:19 PM
Comparing Two Arrays Ides iPhone/iPad Programming 5 Aug 10, 2012 03:56 PM

Forum Jump

All times are GMT -5. The time now is 02:53 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC