can't get rid of warning on cpSpaceAddCollisionPairFunc
-
- Posts: 9
- Joined: Thu Nov 22, 2007 8:21 am
- Contact:
can't get rid of warning on cpSpaceAddCollisionPairFunc
I'm on xCode 3.1.2 trying to build my project but I can't seem to get rid of a warning on arg 4 of cpSpaceAddCollisionPairFunc, where you pass the collision function. It works fine but I am fussy about clean builds so I want to make the warning go away.
I have tried it with and without the & and using int and cpCollFunc as the return type for my function. What am I doing wrong?
edit: the warning is incompatible pointer type.
I have tried it with and without the & and using int and cpCollFunc as the return type for my function. What am I doing wrong?
edit: the warning is incompatible pointer type.
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: can't get rid of warning on cpSpaceAddCollisionPairFunc
That almost certainly means that the function you are trying to pass does not take the correct number/type of parameters. Check it against the type defined in the header.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 9
- Joined: Thu Nov 22, 2007 8:21 am
- Contact:
Re: can't get rid of warning on cpSpaceAddCollisionPairFunc
the chipmunk type def is:
my function prototype is:
I pass it to cpSpace like:
If I try cpCollFunc VM_collision then it complains about two things (something about a cast on the return).
Code: Select all
typedef int (*cpCollFunc)(cpShape *a, cpShape *b, cpContact *contacts, int numContacts, cpFloat normal_coef, void *data);
Code: Select all
int VM_collision(cpShape *s1, cpShape *s2, cpContact* contacts, int numContacts, float normal_coef, void * data);
Code: Select all
cpSpaceAddCollisionPairFunc(VM.sim, 0, 0, &VM_collision, NULL);
-
- Posts: 71
- Joined: Sat Dec 20, 2008 12:16 pm
- Location: Minnesota
- Contact:
Re: can't get rid of warning on cpSpaceAddCollisionPairFunc
What if you change:
to:
or even:
Do you still see the warning then?
Code: Select all
int VM_collision(cpShape *s1, cpShape *s2, cpContact* contacts, int numContacts, float normal_coef, void * data);
Code: Select all
int VM_collision(cpShape *s1, cpShape *s2, cpContact* contacts, int numContacts, cpFloat normal_coef, void * data);]
Code: Select all
static int VM_collision(cpShape *s1, cpShape *s2, cpContact* contacts, int numContacts, cpFloat normal_coef, void * data);
-
- Posts: 9
- Joined: Thu Nov 22, 2007 8:21 am
- Contact:
Re: can't get rid of warning on cpSpaceAddCollisionPairFunc
HA! I found it.
I had changed typedef double cpFloat; to typedef float cpFloat; in chipmunk.h and I forgot to change it back when i got your latest version.
I guess xCode is picky about function pointers. That was the only place it complained.
Thanks for the help on this. It was driving me nuts.
I had changed typedef double cpFloat; to typedef float cpFloat; in chipmunk.h and I forgot to change it back when i got your latest version.
I guess xCode is picky about function pointers. That was the only place it complained.
Thanks for the help on this. It was driving me nuts.
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: can't get rid of warning on cpSpaceAddCollisionPairFunc
Yeah. Looks like someone beat me to it about the cpFloat parameter.
You realize of course that it should be very picky about function pointers. If it wasn't it would allow you to call a function with the wrong types, sizes, or even number of parameters. This is very bad in general. The annoying part is that there are a lot of subtle mistakes that you can make that will work just fine (sometimes only for a specific platform/architecture) but the compiler will complain about.
You realize of course that it should be very picky about function pointers. If it wasn't it would allow you to call a function with the wrong types, sizes, or even number of parameters. This is very bad in general. The annoying part is that there are a lot of subtle mistakes that you can make that will work just fine (sometimes only for a specific platform/architecture) but the compiler will complain about.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 9
- Joined: Thu Nov 22, 2007 8:21 am
- Contact:
Re: can't get rid of warning on cpSpaceAddCollisionPairFunc
I guess I would have found out the hard way if I had ever tried to use normal_coef.
Sadly I'm not even sure what that arg is for.
Sadly I'm not even sure what that arg is for.
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: can't get rid of warning on cpSpaceAddCollisionPairFunc
You multiply it against the normals in the contact array in case Chipmunk had to swap the order of the shapes to satisfy the order defined in the collision pair definition. It will always be 1.0 or -1.0.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Who is online
Users browsing this forum: No registered users and 39 guests