home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / cplus / 12996 < prev    next >
Encoding:
Internet Message Format  |  1992-08-27  |  1.3 KB

  1. Path: sparky!uunet!snorkelwacker.mit.edu!ai-lab!news.ai!ilh
  2. From: ilh@lcs.mit.edu (Lee Hetherington)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: risky inline
  5. Message-ID: <ILH.92Aug27180930@winnie-the-pooh.lcs.mit.edu>
  6. Date: 27 Aug 92 22:09:30 GMT
  7. References: <1992Aug27.142700@uni-paderborn.de>
  8. Sender: news@ai.mit.edu
  9. Reply-To: ilh@lcs.mit.edu
  10. Organization: MIT/LCS Spoken Language Systems
  11. Lines: 26
  12. In-reply-to: trachos@uni-paderborn.de's message of 27 Aug 92 12:27:00 GMT
  13.  
  14. What's the big deal?  You defined (in the header file) C::c() to have
  15. EXTERNAL linkage, but then never provided a GLOBAL definition.  For the
  16. sake of linkage, inline is like static (and turns into that if the
  17. function is actually too big to be inlined).  In the library, your
  18. definition of C::c() is not global.  Why is that so unsafe (or surprising)?
  19.  
  20. The real safety of inline over #define is that you still get type
  21. checking on the arguments and return value.  You also get `overloaded'
  22. function names:
  23.  
  24. inline int min(int a, int b)
  25. {
  26.     return (a <= b) ? a : b;
  27. }
  28.  
  29. inline int min(int a, int b, int c, int d)
  30. {
  31.     int ab = min(a, b), cd = min(c, d);
  32.     return min(ab, cd);
  33. }
  34.  
  35. are two separate functions with the same `name'.  Try that with #define.
  36. --
  37.  
  38.                                 Lee Hetherington
  39.                                 ilh@lcs.mit.edu
  40.