45

I have the following warnings while compiling an openFrameworks 007 project on Visual Studio 2010 SP1:

d:\pedro\development\videoflow\openframeworks\libs\openframeworks\types\ofcolor.h(127): warning C4003: not enough actual parameters for macro 'max'
d:\pedro\development\videoflow\openframeworks\libs\openframeworks\types\ofcolor.h(128): warning C4003: not enough actual parameters for macro 'max'
d:\pedro\development\videoflow\openframeworks\libs\openframeworks\graphics\ofpixels.h(150): warning C4003: not enough actual parameters for macro 'max'
d:\pedro\development\videoflow\openframeworks\libs\openframeworks\graphics\ofpixels.h(151): warning C4003: not enough actual parameters for macro 'max'

From what I could tell this warnings are usually followed by errors but in my case everything works ok. The affected code is below:

const float srcMax = ( (sizeof(SrcType) == sizeof(float) ) ? 1.f : numeric_limits<SrcType>::max() );
const float dstMax = ( (sizeof(PixelType) == sizeof(float) ) ? 1.f : numeric_limits<PixelType>::max() );

I tried to set NOMINMAX on the preprocessor but since openFrameworks also defines NOMINMAX on ofConstants.h I get a bunch of warnings that NOMINMAX is already defined.

I have tried to define NOMINMAX on the affected openFrameworks files but it results on the same warning (in fact if I analyze the files included on ofColor.h and ofPixel.h they end up including ofConstants.h so NOMINMAX should be defined).

Any idea on how to solve this? If you don't... what would be best? This warnings or a bunch of warnings that NOMINMAX is already defined?

EDIT:

BTW when I talked about errors I was talking about these: warning C4003 and errors C2589 and C2059 on: x = std::numeric_limits<int>::max();

I get this (the warning plus 2 errors) if I try to reproduce the problem on a clean C++ project. But on my openFrameworks project I just get the warnings. That's why I get confused!!

Community
  • 1
  • 1
petersaints
  • 1,899
  • 3
  • 18
  • 25

4 Answers4

79

You are not the first to be bitten by these ancient macros. They can't remove them, that would break old code. So they came up with another macro to remove the sting. Make it look like this:

#ifndef NOMINMAX
# define NOMINMAX
#endif
#include <windows.h>
// Rest of your #includes here
//...
Zitrax
  • 19,036
  • 20
  • 88
  • 110
Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
49

Add #undef max to the top of the relevant files.

Seth Carnegie
  • 73,875
  • 22
  • 181
  • 249
  • 8
    Don't forget to `#ifdef max` first. – Puppy Jul 30 '11 at 15:25
  • 2
    @DeadMG why? Is it just good style? I tried it on IdeOne and didn't get any warnings or errors. – Seth Carnegie Jul 30 '11 at 15:27
  • The problem is that the file in question is no my code. It's openFrameworks' code and changing a libraries source code might be a PITA later if the library gets updated. – petersaints Jul 30 '11 at 15:38
  • 6
    @DeadMG: It is permitted to `#undef max` (or any other identifier), even if it is not defined as a macro. – James McNellis Jul 30 '11 at 15:48
  • 3
    I ended up being able to find where the problem was. I was including somewhere else on my code winsock2.h and ws2tcpip.h and these files include windows.h and that was causing the problem. I put #define NOMAXMIN before the includes and it works like a charm now. Neverthless I'm accepting this is answer because it's the correct one to "disable" the min/max macro defined on windows.h while the other answer provides the right thing to do from the start (which is the best thing to do if possible but not really the problem I was facing in the first place). – petersaints Jul 30 '11 at 16:28
  • +1 to Julien-L for actually shedding some light on the root cause of this issue...not sure why no one else did. – arkon Jun 14 '12 at 02:08
  • @petersaints It's not `NOMAXMIN` but `NOMINMAX`: see answer from @hans-passant – Xavier Lamorlette Feb 19 '19 at 15:26
1
#pragma warning (disable: 4003)
Dmitry Kuzminov
  • 6,180
  • 6
  • 18
  • 40
Alex
  • 91
  • 1
  • 2
0
#ifdef _WIN32
#pragma warning(push)
#pragma warning(disable : 4003) 
#endif

... // code with min/max warning you wish to suppress

#ifdef _WIN32
#pragma warning(pop)
#endif
m7913d
  • 10,244
  • 7
  • 28
  • 56
  • 1
    Can you explain your answer, provide a link to relevant official documentation and explain why this answer/solution is better than/preferred over the other(s)? – m7913d Nov 10 '20 at 10:49