chenan2005 / sparsehash

Automatically exported from code.google.com/p/sparsehash
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Error when compiling with class that declare a min or max function visual .net 2005 #29

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Comiling the following file (attach) (on windows, visual .net 2005)
2.
3.

What is the expected output? What do you see instead?
if the undef min if commented, this file does not compile :
error C2059: syntax error : ')'        10
error C2062: type 'int' inattendu       10
error C2143: syntax error : missing ')' before '}' Line    10
error C2143: syntax error : missing ';' before '}' Line    10
error C2143: syntax error : missing '}' before ')' Line    10
error C2238: jetons inattendus before ';'   Line    10
error C2334: jetons inattendus before ':' ; corps apparent de la fonction
ignoré Line    10
error C2059: syntax error : '}'    Line    11
error C2059: syntax error : '}'    Line    11
error C2143: syntax error : missing ';' before '}' Line    11
error C2143: syntax error : missing ';' before '}' Line    11
error C2059: syntax error : '('    Line    18

if undef min is not commented, it compile well. Unfortunately our code has
a lot of min and max function, cannot change them all.

What version of the product are you using? On what operating system?
windows xp sp2, visual compiler .net 2005 sp1 (french)

Please provide any additional information below.

Thanks Laurent

Original issue reported on code.google.com by L.VanMiegroet on 24 Feb 2009 at 4:30

Attachments:

GoogleCodeExporter commented 9 years ago
I tried compiling this on unix, and it worked fine.  So I believe the problem is
likely that some windows header file somewhere is defining min. This post 
suggests
it's windows.h:

 https://www-old.cae.wisc.edu/pipermail/octave-maintainers/2007-February/001812.html

But it's hard for me to believe you wouldn't have seen this problem before, 
because
other code -- perhaps code you've written -- must include windows.h as well!  So
maybe it's somewhere else?

Try this: edit src/windows/google/sparseconfig.h, and after the line
   #include <windows.h>
add the lines
   #undef min
   #undef max

Does this fix the problem for you?

Original comment by csilv...@gmail.com on 24 Feb 2009 at 7:22

GoogleCodeExporter commented 9 years ago
Hi, 

Your correction fixed the problem. We hadn't the problem before because we never
include windows.h. Moreover, i've seen that it is in windef.h (included from
windows.h ) that min and max macros are defined.

Thank you very much
Laurent

Original comment by L.VanMiegroet on 25 Feb 2009 at 10:21

GoogleCodeExporter commented 9 years ago
Hmm, I'm not sure what to do about this.  I can't just #undef min in my .h file,
since folks may write windows programs that legitimately depend on the 'min' in
winbase.h.  I don't want their code to break when they include one of the 
sparsehash
header files.

On the other hand, sparsehash needs some of the code in windows.h to work 
properly.

The basic problem is that a fundamental windows header file defines macros with
common names like min and max; but there's nothing we can do about that now. 
:-(  I
think you may have to just keep the #undef min as a local change.  I'll look 
into
whether there's anything better we can do.

Original comment by csilv...@gmail.com on 25 Feb 2009 at 8:34

GoogleCodeExporter commented 9 years ago
On further investigation, it looks like sparsehash doesn't need windows.h after 
all.
 So I just removed the #include entirely.  This should be fixed in the next version
of sparsehash.

Original comment by csilv...@gmail.com on 25 Feb 2009 at 8:42

GoogleCodeExporter commented 9 years ago
This should be fixed in sparsehash 1.5, just released.

Original comment by csilv...@gmail.com on 7 May 2009 at 3:10