home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / os / linux / 17299 < prev    next >
Encoding:
Text File  |  1992-11-20  |  1.7 KB  |  54 lines

  1. Newsgroups: comp.os.linux
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!moe.ksu.ksu.edu!ux1.cso.uiuc.edu!news.cso.uiuc.edu!ehsn11.cen.uiuc.edu!jy10033
  3. From: jy10033@ehsn11.cen.uiuc.edu (Joshua M Yelon)
  4. Subject: function-->macro bugs.
  5. Message-ID: <By0ows.95I@news.cso.uiuc.edu>
  6. Sender: usenet@news.cso.uiuc.edu (Net Noise owner)
  7. Organization: University of Illinois at Urbana
  8. Date: Fri, 20 Nov 1992 13:46:03 GMT
  9. Lines: 43
  10.  
  11.  
  12. Our "stdlib.h" does something unusual: it defines malloc as a macro.
  13. According to the standard, though, malloc is a function.  Indeed,
  14. there are many functions that have been converted to macros by our
  15. header files.
  16.  
  17.  
  18. Here's why it's wrong to make a function into a macro:
  19.  
  20. 1. This is correct:
  21.  
  22. extern void *malloc();
  23.  
  24. but if I put it in my program, and malloc is a macro, it will crash,
  25. saying "malloc called with zero arguments." 
  26.  
  27. 2. This is correct:
  28.  
  29. void *(*allocator)() = malloc;
  30.  
  31. this is also correct, but it will come back with "undefined external:
  32. malloc" if malloc is a macro.
  33.  
  34. 3. This is correct:
  35.  
  36. /* My-super-efficient-malloc: */
  37. static void *malloc(n)
  38. int n;
  39. {...
  40.  
  41. but it will blow up if malloc is a macro.
  42.  
  43. In case you think these are far-fetched examples, and you don't think
  44. they are likely to bite us, I'd like to point out that both emacs 18.59
  45. and f2c _would_ compile out-of-the-box, but don't because of these errors.
  46.  
  47. I'd like to get these errors repaired, but when I wrote to HLU, he
  48. gave me a "solution" involving compiler switches, and did not seem to
  49. recognize this as an actual bug that requires proper repair.  Since I
  50. do not have any desire to argue the point with him, I have dropped
  51. this message into a public place, so that this group can solve the
  52. problem or ignore it as it sees fit.
  53.  
  54.