home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / std_unix / volume.27 / text0003.txt < prev    next >
Encoding:
Text File  |  1992-05-20  |  1.2 KB  |  37 lines

  1. Submitted-by: barmar@think.com (Barry Margolin)
  2.  
  3. In article <1992Feb22.073646.18830@uunet.uu.net> cmr@cvedc.prime.com (Chesley Reyburn) writes:
  4. >Thank you!  I sent mail yesterday to Mr. Lewine stating the same
  5. >thing and proposing something like:
  6. >    
  7. >    void *(*local_func())(char *filename, char *entryname)
  8. ...
  9. >The only problem that I can see is that the above function
  10. >limits the new functions to always only returning a pointer
  11. >to void.
  12.  
  13. I don't think that's a problem.  The caller should be required to cast the
  14. returned pointer to the actual type of the function that is being linked
  15. in.  So, if you're trying to dynamically load a function that returns an
  16. int, you would write:
  17.  
  18. int (*foo_fun)();
  19. foo_fun = (int (*)()) local_func(filename, entryname);
  20.  
  21. BTW, why did you specify void* in the first place?  Since the default
  22. return type in C is int, it would probably be more intuitive for
  23. local_func() to return an int function rather than a void* function.
  24. Another reasonable default would be a void function.  But either way, the
  25. caller will have to cast it if the default isn't appropriate for that
  26. function.
  27.  
  28. -- 
  29. Barry Margolin
  30. System Manager, Thinking Machines Corp.
  31.  
  32. barmar@think.com          {uunet,harvard}!think!barmar
  33.  
  34.  
  35. Volume-Number: Volume 27, Number 4
  36.  
  37.