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
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 offline   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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 04:43 PM.

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

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