Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > typedef problem

typedef problem
Thread Tools
Dedicated MacNNer
Join Date: Jun 2000
Location: Dundas, Ontario, Canada
Status: Offline
Reply With Quote
Sep 6, 2001, 02:25 PM
 
Hello,

I am a little out of practice with my pure C (been working purely in the API a little too long) knowledge and this is causing me a problem. I am defining a type in my program to allow me to pass an integer array between objective-C methods.

In the header file, I say this:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier> <font color = green>typedef</font> <font color = green>int</font> intArray[<font color = blue>16</font>]</font>[/code]
and then in the program I try to do this:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier> tempBoard = theBoard;
</font>[/code]
Where these are both type intArray (I even tried it when defining tempBoard as int tempBoard[16] ) but I get a compile error saying that they are incompatible types.

I know that this must be very simple but I can't remember what problems like this are caused by.

Please help,
Jeff.

[ 09-06-2001: Message edited by: Apocalypse ]

Note: Never try to edit a post that has code tags in it.

[ 09-06-2001: Message edited by: Apocalypse ]
Spectral Class
"Shedding Light on Innovation"
     
Forum Regular
Join Date: Oct 2000
Location: Portland, OR USA
Status: Offline
Reply With Quote
Sep 6, 2001, 02:37 PM
 
I think you want something like:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
<font color = green>typedef</font> <font color = green>int</font>[<font color = blue>16</font>] intArray;
</font>[/code]
     
Dedicated MacNNer
Join Date: Jun 2000
Location: Dundas, Ontario, Canada
Status: Offline
Reply With Quote
Sep 6, 2001, 07:54 PM
 
No, that is not correct at all.

At another point in the program I do try to assign a value to a specific element of the type and that gives no error. Perhaps the problem is that you cannot define one array as equal to another. I don't know but I think that if I move each element at once, it might work.

Anyone know why this behavior is?

thanks,
Jeff.
Spectral Class
"Shedding Light on Innovation"
     
Fresh-Faced Recruit
Join Date: Sep 2001
Status: Offline
Reply With Quote
Sep 7, 2001, 12:30 PM
 
Gotta love pointers.

If you want tempBoard to alias the memory occupied by theBoard do this:

int theBoard[16];
int *tempBoard;

tempBoard = theBoard;

If you want to copy the contents of theBoard to tempBoard do this:

int theBoard[16];
int tempBoard[16];

bcopy(theBoard, tempBoard, 16 * sizeof(int));
or
memcpy(tempBoard, theBoard, 16 * sizeof(int));
     
   
Thread Tools
Forum Links
Forum 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
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 02:56 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2