 |
 |
typedef problem
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Jun 2000
Location: Dundas, Ontario, Canada
Status:
Offline
|
|
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 ]
|
|
|
| |
|
|
|
 |
|
 |
|
Forum Regular
Join Date: Oct 2000
Location: Portland, OR USA
Status:
Offline
|
|
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
|
|
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.
|
|
|
| |
|
|
|
 |
|
 |
|
Fresh-Faced Recruit
Join Date: Sep 2001
Status:
Offline
|
|
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));
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|