
| -----Original Message----- | From: boost-bounces@lists.boost.org | [mailto:boost-bounces@lists.boost.org] On Behalf Of Martin Bonner | Sent: 26 June 2006 11:59 | To: boost@lists.boost.org | Subject: Re: [boost] [test] test/included min max macro issue | | ----Original Message---- | From: boost-bounces@lists.boost.org | [mailto:boost-bounces@lists.boost.org] On Behalf Of Paul A Bristow | Sent: 24 June 2006 14:34 To: boost@lists.boost.org | Subject: Re: [boost] [test] test/included min max macro issue | | > A further quick question on this problem. | > | > It is my custom (having a strong view that it aids readers - | > including me - | > of my programs) to write | > | > #include <limits> | > using std::numeric_limits; | > | > How do I avoid min/max macro problems when writing, for example, | > | > return numeric_limits<double>::max(); ? | >From the website: | >> > # If you want to call std::numeric_limits<int>::max(), use | >> > (std::numeric_limits<int>::max)() instead.> | | The basic rule is that you must never have the (pp-)tokens | "max" and "(" | one after the other. If you do, the preprocessor will try | to expand the max macro. | | The solution is to wrap the function name in parens, so what | you would write is: | | return (numeric_limits<double::max)(); | | That means the preprocessor sees "max" and ")", and doesn't try to | expand the macro. Thanks, I am now better disambiguated - if at present macro vulnerable ;-( Perhaps Tonto can add this to the Boost Guidelines ;-) Paul --- Paul A Bristow Prizet Farmhouse, Kendal, Cumbria UK LA8 8AB +44 1539561830 & SMS, Mobile +44 7714 330204 & SMS pbristow@hetp.u-net.com