Can't get code to work properly
I'm not entirely sure I'm doing this right.
Shouldn't it be printing out 1, 3, and 5?
It prints out 0, 0, 0.
Any help on this matter
Code:
typedef struct
{
int a[3];
} SomeType;
SomeType lala;
- (void)setVertices:(SomeType)v :(int)x :(int)y :(int)z {
v.a[0] = x;
v.a[1] = y;
v.a[2] = z;
}
- (void)test {
[self setVertices:lala :1 :3 :5];
printf("%i, %i, %i", lala.a[0], lala.a[1], lala.a[2]);
}Shouldn't it be printing out 1, 3, and 5?
It prints out 0, 0, 0.
Any help on this matter
Nope. In the code you pasted, -setVertices:::: is modifying a local copy of a SomeType, since that's the way you're passing it. The SomeType in -test remains unaltered.
Is there anyway to fix it so that the values are assigned?
I have a different piece of code working fine but it's like this:
This works fine but I cannot seem to "reset" it all back to 0 and I'm having problems debugging it with NSLog and printf, so I decided to change it around a bit.
EDIT:
Well, I moved the printf function inside of -setVertices and it seems like it works =/
I have a different piece of code working fine but it's like this:
Code:
typedef float MapVertex[3];
typedef float MapTexCoord[2];
MapVertex mapVerticesLayer1[15000];
MapTexCoord mapTexCoords[15000];
MapVertex mapVerticesLayer2[15000];
MapTexCoord mapTexCoordsLayer2[15000];
- (void)setMapVertices:(MapVertex)v :(float)x :(float)y :(float)z {
v[0] = x;
v[1] = y;
v[2] = z;
}
- (void)setMapTexCoords:(MapTexCoord)v :(float)x :(float)y {
v[0] = x;
v[1] = y;
}EDIT:
Well, I moved the printf function inside of -setVertices and it seems like it works =/
jeonghyunhan Wrote:EDIT:
Well, I moved the printf function inside of -setVertices and it seems like it works =/
Of course, because you're printing out the function's local copy of the struct. It sounds like you may need to brush up on some C fundamentals. I'd give you the answer, but you're better off reaching it by your own understanding, since this would cripple you in future coding.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| How to get part of code to work | jeonghyunhan | 2 | 2,619 |
Feb 12, 2009 09:31 AM Last Post: ThemsAllTook |
|

