home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.linux
- 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
- From: jy10033@ehsn11.cen.uiuc.edu (Joshua M Yelon)
- Subject: function-->macro bugs.
- Message-ID: <By0ows.95I@news.cso.uiuc.edu>
- Sender: usenet@news.cso.uiuc.edu (Net Noise owner)
- Organization: University of Illinois at Urbana
- Date: Fri, 20 Nov 1992 13:46:03 GMT
- Lines: 43
-
-
- Our "stdlib.h" does something unusual: it defines malloc as a macro.
- According to the standard, though, malloc is a function. Indeed,
- there are many functions that have been converted to macros by our
- header files.
-
-
- Here's why it's wrong to make a function into a macro:
-
- 1. This is correct:
-
- extern void *malloc();
-
- but if I put it in my program, and malloc is a macro, it will crash,
- saying "malloc called with zero arguments."
-
- 2. This is correct:
-
- void *(*allocator)() = malloc;
-
- this is also correct, but it will come back with "undefined external:
- malloc" if malloc is a macro.
-
- 3. This is correct:
-
- /* My-super-efficient-malloc: */
- static void *malloc(n)
- int n;
- {...
-
- but it will blow up if malloc is a macro.
-
- In case you think these are far-fetched examples, and you don't think
- they are likely to bite us, I'd like to point out that both emacs 18.59
- and f2c _would_ compile out-of-the-box, but don't because of these errors.
-
- I'd like to get these errors repaired, but when I wrote to HLU, he
- gave me a "solution" involving compiler switches, and did not seem to
- recognize this as an actual bug that requires proper repair. Since I
- do not have any desire to argue the point with him, I have dropped
- this message into a public place, so that this group can solve the
- problem or ignore it as it sees fit.
-
-