Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

problems with new boost lib
I'm in the process of updating from boost 1.31 to 1.32.  I have a header
file
that stores some constants for numeric limits.
It looks like this:

// usual header guards
#include <limits> // for numeric_limits
const float maxFloat = std::numeric_limits<float>::max();
//

I get the following errors for each line in the header file:


 c:\MSVC\Projects\Common\numeric_constant
s.h(6) : warning C4003: not enough
actual parameters for macro 'max'
 c:\MSVC\Projects\Common\numeric_constant
s.h(6) : error C2589: '(' : illegal
token on right side of '::'
 c:\MSVC\Projects\Common\numeric_constant
s.h(6) : error C2059: syntax error :
'::'
 c:\MSVC\Projects\Common\numeric_constant
s.h(6) : error C2059: syntax error :
')'
 c:\MSVC\Projects\Common\numeric_constant
s.h(6) : error C2059: syntax error :
')'

It seems that it thinks that max is a macro.  Am I missing an include or
something?


Report this thread to moderator Post Follow-up to this message
Old Post
Duane Hebert
04-06-05 05:52 PM


Re: problems with new boost lib
"Duane Hebert" <spoo@flarn.com> wrote in message
news:OStotfeOFHA.244@TK2MSFTNGP12.phx.gbl...
> I'm in the process of updating from boost 1.31 to 1.32.  I have a header
> file
> that stores some constants for numeric limits.
> It looks like this:
>
> // usual header guards
> #include <limits> // for numeric_limits
> const float maxFloat = std::numeric_limits<float>::max();

I found one solution on the boost site:

const float maxFloat = (std::numeric_limits<float>::max)();

Macros s*ck.


Report this thread to moderator Post Follow-up to this message
Old Post
Duane Hebert
04-06-05 05:52 PM


Re: problems with new boost lib
Duane Hebert wrote:
> I'm in the process of updating from boost 1.31 to 1.32.  I have a
> header file
> that stores some constants for numeric limits.
> It looks like this:
>
> // usual header guards
> #include <limits> // for numeric_limits
> const float maxFloat = std::numeric_limits<float>::max();
> //
>
> I get the following errors for each line in the header file:
>
>
>  c:\MSVC\Projects\Common\numeric_constant
s.h(6) : warning C4003: not
> enough actual parameters for macro 'max'
>  c:\MSVC\Projects\Common\numeric_constant
s.h(6) : error C2589: '(' :
> illegal token on right side of '::'
>  c:\MSVC\Projects\Common\numeric_constant
s.h(6) : error C2059: syntax
> error : '::'
>  c:\MSVC\Projects\Common\numeric_constant
s.h(6) : error C2059: syntax
> error : ')'
>  c:\MSVC\Projects\Common\numeric_constant
s.h(6) : error C2059: syntax
> error : ')'
>
> It seems that it thinks that max is a macro.  Am I missing an include
> or something?

max IS a macro, unfortunately, if you've #included <windows.h> (thanks to
the Platform SDK group years ago).

You can #define NO_MINMAX before including windows.h to prevent the macros.

You can also re-phrase your code:

const float maxFloat = std::numeric_limits<float>::(max)();

That odd looking syntax is still a valid function invocation in C++, but it
won't be recognized as a use of the max(a,b) macro by the preprocessor.

-cd



Report this thread to moderator Post Follow-up to this message
Old Post
Carl Daniel [VC++ MVP]
04-06-05 05:52 PM


Re: problems with new boost lib
> It seems that it thinks that max is a macro.

Which it may do if you are including <windows.h> which defines those
non-standard macros.
Have you defined NOMINMAX  before including it?

Stephen Howe





Report this thread to moderator Post Follow-up to this message
Old Post
Stephen Howe
04-06-05 05:52 PM


Re: problems with new boost lib
"Carl Daniel [VC++ MVP]" <cpdaniel_remove_this_and_nospam@mvps.org.nospam>
wrote in message news:eWblhzeOFHA.3928@TK2MSFTNGP09.phx.gbl...

> max IS a macro, unfortunately, if you've #included <windows.h> (thanks to
> the Platform SDK group years ago).

> You can #define NO_MINMAX before including windows.h to prevent the
macros.

We're not directly including windows.h anywhere but we are doing unmanaged
c++ with Qt.  Either Qt or boost must be pulling it in.

> You can also re-phrase your code:
>
> const float maxFloat = std::numeric_limits<float>::(max)();
>
> That odd looking syntax is still a valid function invocation in C++, but
it
> won't be recognized as a use of the max(a,b) macro by the preprocessor.

That particular syntax didn't seem to work.  I think it has to do with the
namespaces.  This does seem to work:

const float maxFloat = (std::numeric_limits<float>::max)();

Thanks for the suggestion though.  Funny thing is that this didn't happen
with the previous version of boost.


Report this thread to moderator Post Follow-up to this message
Old Post
Duane Hebert
04-06-05 05:52 PM


Re: problems with new boost lib
"Stephen Howe" <stephenPOINThoweATtns-globalPOINTcom> wrote in message
news:Ok2440eOFHA.3336@TK2MSFTNGP09.phx.gbl... 
>
> Which it may do if you are including <windows.h> which defines those
> non-standard macros.
> Have you defined NOMINMAX  before including it?

We're not directly including it.  Either boost or Qt may be.
At any rate, I bracketed the calls to max as suggested by Carl
in another post and this seems to work.

One of my favorite things about winapi stuff is the macros <g>
Normally I get bit by the "somefunctionA" is not a member due
to the Unicode macros.


Report this thread to moderator Post Follow-up to this message
Old Post
Duane Hebert
04-06-05 05:52 PM


Re: problems with new boost lib
"Duane Hebert" <spoo@flarn.com> wrote in message
news:u8eSJDfOFHA.2604@TK2MSFTNGP10.phx.gbl...
> "Carl Daniel [VC++ MVP]" <cpdaniel_remove_this_and_nospam@mvps.org.nospam>
> wrote in message news:eWblhzeOFHA.3928@TK2MSFTNGP09.phx.gbl... 
>
> That particular syntax didn't seem to work.  I think it has to do with the
> namespaces.  This does seem to work:
>
> const float maxFloat = (std::numeric_limits<float>::max)();

Yeah - I forgot to include the namespace inside the ().

-cd



Report this thread to moderator Post Follow-up to this message
Old Post
Carl Daniel [VC++ MVP]
04-06-05 05:52 PM


Re: problems with new boost lib
Macros strike again!
min/max macros are frequent offenders. So when I create a header file for
public consumption when I can't know what is included before it, I always
start with:
#undef min
#undef max

"Duane Hebert" <spoo@flarn.com> wrote in message
news:OStotfeOFHA.244@TK2MSFTNGP12.phx.gbl...
> I'm in the process of updating from boost 1.31 to 1.32.  I have a header
> file
> that stores some constants for numeric limits.
> It looks like this:
>
> // usual header guards
> #include <limits> // for numeric_limits
> const float maxFloat = std::numeric_limits<float>::max();
> //
>
> I get the following errors for each line in the header file:
>
>
>  c:\MSVC\Projects\Common\numeric_constant
s.h(6) : warning C4003: not enough
> actual parameters for macro 'max'
>



Report this thread to moderator Post Follow-up to this message
Old Post
Gene Bushuyev
04-06-05 05:52 PM


Re: problems with new boost lib
"Gene Bushuyev" <gb@127.0.0.1> wrote in message news:dAz4e.1776$qD2.612@newssvr14.news.prod
igy.com...
> Macros strike again!
> min/max macros are frequent offenders. So when I create a header file for
> public consumption when I can't know what is included before it, I always
> start with:
> #undef min
> #undef max

That was actually my first solution<g>
We use some 3rd partly libs though and I would hate to
update one that pulled in some redef of min or max
later.  I went with the bracketing the function idea.
I wonder if MS will ever get rid of all these macros <g>



Report this thread to moderator Post Follow-up to this message
Old Post
Duane Hebert
04-06-05 05:52 PM


Re: problems with new boost lib
Why would microsoft get rid of min and max macro's?
So to be compatible with standards? Since when is that a priority for M$? :)

"Duane Hebert" <spoo@flarn2.com> wrote in message
news:uYIP94jOFHA.204@TK2MSFTNGP15.phx.gbl...
>
> "Gene Bushuyev" <gb@127.0.0.1> wrote in message
> news:dAz4e.1776$qD2.612@newssvr14.news.prodigy.com... 
>
> That was actually my first solution<g>
> We use some 3rd partly libs though and I would hate to
> update one that pulled in some redef of min or max
> later.  I went with the bracketing the function idea.
> I wonder if MS will ever get rid of all these macros <g>
>
>



Report this thread to moderator Post Follow-up to this message
Old Post
Lisa Pearlson
04-12-05 09:00 AM


Sponsored Links




Last Thread Next Thread Next
Pages (2): [1] 2 »
Search this forum -> 
Post New Thread

VC STL archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 03:54 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.