Function Pointer Problem

3 posts / 0 new
Last post
broadblues
broadblues's picture
Offline
Last seen: 4 years 10 months ago
Joined: 2012-05-02 21:48
Function Pointer Problem

Hi,

I have this code:

  1. float pcm_multiply(float src, float dest)
  2. {
  3. return src * dest * inv255;
  4. }
  5.  
  6. float pcm_divide(float src, float dest)
  7. {
  8. return 255.0 * dest / (src + 1.0);
  9. }
  10.  
  11. struct PixelCombineModes pcm[] = {
  12. { PCM_BLEND, "Normal", NULL },
  13. { PCM_MULTIPLY, "Multiply", pcm_multiply},
  14. { PCM_DIVIDE, "Divide", pcm_divide},
  15. { PCM_NUMMODES, NULL, NULL }
  16. };
  17.  
  18. UWORD FindPCFByName(struct PixelCombineModes *pcm, STRPTR name)
  19. {
  20. UWORD result = NULL;
  21. int _index = 0;
  22. IDOS->Printf(" Finding %s\n",name);
  23. while((pcm[_index].pcm_Name != NULL))
  24. {
  25. if(!(strcmp(name,pcm[_index].pcm_Name)))
  26. {
  27. result = pcm[_index].pcm_PCF;
  28. break;
  29. }
  30. _index ++;
  31. }
  32. IDOS->Printf(" Setting function to %08lx\n",result);
  33. return result;
  34. }
  35.  
  36. BOOL SetLayerPCFByName(struct SketchLayer *sklay, STRPTR name)
  37. {
  38.  
  39. if(name)
  40. {
  41. if((sklay->sl_PCF = FindPCFByName(pcm, name)))
  42. {
  43. return TRUE;
  44. }
  45. }
  46. return FALSE;
  47. }

The function FindPFCByName seems to return 0x00007300 when called for "Multiply", which is clearly not the address of pcm_multiply

Any ideas why this might not work?

tboeckel
tboeckel's picture
Offline
Last seen: 4 years 6 months ago
Joined: 2011-09-13 12:32
The UWORD type is only 16

The UWORD type is only 16 bits wide, not 32 bits as would be required for a pointer.

Better tune your compiler settings. Something like "UWORD result = NULL" should have raised a warning already, because you are assigning a pointer type to a an integer variable.

broadblues
broadblues's picture
Offline
Last seen: 4 years 10 months ago
Joined: 2012-05-02 21:48
Thanks! I knew it would be

Thanks!

I knew it would be something so obvious I couldn't see it.

I cut paste the framework of the code from a function that returned a UWORD and forgot to update that bit.

Log in or register to post comments