home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / os / os2 / programm / 4349 < prev    next >
Encoding:
Text File  |  1992-08-20  |  2.7 KB  |  80 lines

  1. Xref: sparky comp.os.os2.programmer:4349 comp.os.os2.misc:27856
  2. Path: sparky!uunet!vnet.ibm.com
  3. From: dmm@vnet.ibm.com (dave)
  4. Message-ID: <19920820.121934.870@almaden.ibm.com>
  5. Date: Thu, 20 Aug 92 13:43:25 EDT
  6. Newsgroups: comp.os.os2.programmer,comp.os.os2.misc
  7. Subject: Re: C Set/2
  8. Organization: IBM Canada Lab
  9. News-Software: UReply 3.0
  10. X-X-From: dmm@vnet.ibm.com (Dave Mooney)
  11. References: <1992Aug19.203811.15056@natinst.com>
  12. Lines: 66
  13.  
  14. In <1992Aug19.203811.15056@natinst.com> Uma Arunkumar writes:
  15. > (restructured a bit -- dmm)
  16. >
  17. >   struct {
  18. >          short a;
  19. >          short b;
  20. >          short (* fun_name)();
  21. >   } command;
  22. >
  23. >   extern short Test1(short p, short q, short r);
  24. >   extern short Test2(short x, short y);
  25. >
  26. >   commands cmd_array[] = {
  27. >                              {1,    2,   Test1}
  28. >                              {3,    4,   Test2}
  29. >   };
  30. >
  31. >   icc /c /w3 /o+ prog1.c prog1a.h prog1b.h
  32. >
  33. >       1. error EDC0227 : The return types of the functionm pointers are incompatible.
  34. >       2. informational EDC0140: Operand has type pointer to _Optlink function returning signed short integer.
  35. >       3. informational EDC0140: Operand has type _Optlink function returning signed short integer.
  36.  
  37. First of all, the error message is lying to you.  It's not the return
  38. types of the function pointers which are incompatible -- it's the
  39. parameter lists.  Your example can be chopped down to:
  40.  
  41.   int f(short);
  42.   int (*fp)();
  43.  
  44.   fp = f;
  45.  
  46. For two function pointers to be compatible, their parameters lists must
  47. be compatible.  If one of the parameter lists is empty and one isn't, all
  48. the parameters in the non-empty list must be wide types (ie, not char,
  49. short, or float).  All the gory details are in section 3.5.4.3 of the
  50. ANSI C Standard, but the upshot is that a function with a short parameter
  51. is not compatible with a function pointer with no parameters.
  52.  
  53. We are easing up on this restriction in our next release (for the benefit
  54. of people like you, whose code suddenly stops working), but in the mean
  55. time, you can get around this problem by sticking in explicit casts on
  56. the assignments:
  57.  
  58.   typedef short (* fptype)();
  59.  
  60.   typedef struct {
  61.          short a;
  62.          short b;
  63.          fptype fun_name;
  64.   } command;
  65.  
  66.   extern short Test1(short p, short q, short r);
  67.   extern short Test2(short x, short y);
  68.  
  69.   command cmd_array[] = {
  70.                              {1,    2,   (fptype)Test1},
  71.                              {3,    4,   (fptype)Test2}
  72.   };
  73.  
  74. dave
  75.  
  76. -------------------------------------------------------------------------
  77. Dave Mooney                                              dmm@vnet.ibm.com
  78.  C Set/2 Development, IBM Canada Lab, 844 Don Mills Rd, Toronto, Ontario
  79.             "If you've got a blacklist, I want to be on it"
  80.