home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / cplus / 19887 < prev    next >
Encoding:
Internet Message Format  |  1993-01-25  |  1.6 KB

  1. Path: sparky!uunet!stanford.edu!agate!darkstar.UCSC.EDU!cats.ucsc.edu!spencer
  2. From: spencer@cats.ucsc.edu (Michael Spencer)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Function 'max' should have a prototype
  5. Date: 25 Jan 1993 23:36:38 GMT
  6. Organization: University of California, Santa Cruz
  7. Lines: 32
  8. Message-ID: <1k1ti6INNe6c@darkstar.UCSC.EDU>
  9. References: <hrpctw.14@pnv.palm.cri.nz>
  10. NNTP-Posting-Host: am.ucsc.edu
  11.  
  12.  
  13. hrpctw@pnv.palm.cri.nz (Colin T. Wilson-Salt) writes:
  14.  
  15. >I can't seem to get the max() macro to work.  It works OK under C, but
  16. >under C++ it gives me the error "Function 'max' should have a prototype".
  17.  
  18. >Should I give up and write a replacement max() function/macro?
  19.  
  20. Roll your own. It's a lot easier than trying to figure out the
  21. vagaries of compilers!  Try:
  22.  
  23. #define Minim(a,b)            ((a<b) ? a : b)
  24. #define Maxim(a,b)            ((a>b) ? a : b)
  25. #define InRange(a,lo,hi)      ((a<lo) ? 0 : ((a>hi) ? 0 : 1))
  26. #define RangeSet(a,lo,hi)     ((a<lo) ? (a = lo) : (a>hi) ? (a = hi) : a )
  27. #define CircleSet(a,lo,hi)    ((a<lo) ? (a = hi) : (a>hi) ? (a = lo) : a )
  28.  
  29. The last 3 will help avoid 'fence-post' errors.
  30.  
  31.  
  32. ===========================================================================
  33. Michael Spencer            |      2640 Borregas
  34. spencer@cats.ucsc.edu      |      Aptos, CA   95003
  35. ===========================================================================
  36.  
  37. -- 
  38.  
  39. ===========================================================================
  40. Michael Spencer            |      2640 Borregas
  41. spencer@cats.ucsc.edu      |      Aptos, CA   95003
  42. ===========================================================================
  43.  
  44.