tags:

views:

59

answers:

1

I have a big project with a bunch of .cc files that have mostly c code and some c++ code. I want to use a vector in this program since I need an unbounded data type that is simple to make 2d (in other words I don't want to use an array or a list). The problem is that when I run my make after including the vector class I get errors that I didn't get before. The only line that makes any difference is #include <vector>. I did not write the make files (and there are about 4 or 5 of them) but to the best of my knowledge it is using the GNU compiler. I have no vector objects instantiated, already included using namespace std; and the error goes away when I comment out the include directive for vector. On another file in this project however I used the queue library and it didn't have any problem with it. The problem happens when I include it in a .h file, it has no problem with .cc files, but since I will need to instantiate a vector object in the .h file I don't have the commodity of only using .cc files for this. Can someone give me any help for this problem?

Here is the output copied pasted from bash for the part that leads up to the error:

g++ -g -Wall -m32 -Wshadow -I../bin -I../filesys -I../userprog -I../threads -I../machine 
-DUSER_PROGRAM -DFILESYS_NEEDED -DFILESYS_STUB -DHOST_i386 -DCHANGED -c ../threads/main.cc

g++ -g -Wall -m32 -Wshadow -I../bin -I../filesys -I../userprog -I../threads -I../machine 
-DUSER_PROGRAM -DFILESYS_NEEDED -DFILESYS_STUB -DHOST_i386 -DCHANGED -c ../threads
/scheduler.cc

g++ -g -Wall -m32 -Wshadow -I../bin -I../filesys -I../userprog -I../threads -I../machine 
-DUSER_PROGRAM -DFILESYS_NEEDED -DFILESYS_STUB -DHOST_i386 -DCHANGED -c ../threads/synch.cc

g++ -g -Wall -m32 -Wshadow -I../bin -I../filesys -I../userprog -I../threads -I../machine 
-DUSER_PROGRAM -DFILESYS_NEEDED -DFILESYS_STUB -DHOST_i386 -DCHANGED -c ../threads
/system.cc

g++ -g -Wall -m32 -Wshadow -I../bin -I../filesys -I../userprog -I../threads -I../machine 
-DUSER_PROGRAM -DFILESYS_NEEDED -DFILESYS_STUB -DHOST_i386 -DCHANGED -c ../threads
/thread.cc

g++ -g -Wall -m32 -Wshadow -I../bin -I../filesys -I../userprog -I../threads -I../machine 
-DUSER_PROGRAM -DFILESYS_NEEDED -DFILESYS_STUB -DHOST_i386 -DCHANGED -c ../threads
/threadtest.cc

g++ -g -Wall -m32 -Wshadow -I../bin -I../filesys -I../userprog -I../threads -I../machine 
-DUSER_PROGRAM -DFILESYS_NEEDED -DFILESYS_STUB -DHOST_i386 -DCHANGED -c ../machine
/interrupt.cc

g++ -g -Wall -m32 -Wshadow -I../bin -I../filesys -I../userprog -I../threads -I../machine 
-DUSER_PROGRAM -DFILESYS_NEEDED -DFILESYS_STUB -DHOST_i386 -DCHANGED -c ../machine
/sysdep.cc

In file included from /usr/include/c++/4.4/vector:61,

                 from ../threads/system.h:19,

                 from ../machine/sysdep.cc:77:

/usr/include/c++/4.4/bits/stl_algobase.h:232:56: error: macro "min" passed 3 arguments, 
but takes just 2

/usr/include/c++/4.4/bits/stl_algobase.h:253:56: error: macro "max" passed 3 arguments, 
but takes just 2

In file included from /usr/include/c++/4.4/vector:61,

                 from ../threads/system.h:19,

                 from ../machine/sysdep.cc:77:

/usr/include/c++/4.4/bits/stl_algobase.h:186: error: expected unqualified-id before ‘const’

/usr/include/c++/4.4/bits/stl_algobase.h:186: error: expected ‘)’ before ‘const’

/usr/include/c++/4.4/bits/stl_algobase.h:186: error: expected ‘)’ before ‘const’

/usr/include/c++/4.4/bits/stl_algobase.h:186: error: expected ‘)’ before ‘const’

/usr/include/c++/4.4/bits/stl_algobase.h:186: error: expected initializer before ‘const’

/usr/include/c++/4.4/bits/stl_algobase.h:209: error: expected unqualified-id before ‘const’

/usr/include/c++/4.4/bits/stl_algobase.h:209: error: expected ‘)’ before ‘const’

/usr/include/c++/4.4/bits/stl_algobase.h:209: error: expected ‘)’ before ‘const’

/usr/include/c++/4.4/bits/stl_algobase.h:209: error: expected ‘)’ before ‘const’

/usr/include/c++/4.4/bits/stl_algobase.h:209: error: expected initializer before ‘const’

/usr/include/c++/4.4/bits/stl_algobase.h:232: error: ‘std::min’ declared as an ‘inline’ 
variable

/usr/include/c++/4.4/bits/stl_algobase.h:232: error: template declaration of ‘const _Tp& 
std::min’

/usr/include/c++/4.4/bits/stl_algobase.h:235: error: expected primary-expression before 
‘if’

/usr/include/c++/4.4/bits/stl_algobase.h:235: error: expected ‘}’ before ‘if’


/usr/include/c++/4.4/bits/stl_algobase.h:237: error: expected unqualified-id before 
‘return’

/usr/include/c++/4.4/bits/stl_algobase.h:253: error: ‘max’ declared as an ‘inline’ variable

/usr/include/c++/4.4/bits/stl_algobase.h:253: error: template declaration of ‘const _Tp& 
max’

/usr/include/c++/4.4/bits/stl_algobase.h:256: error: expected primary-expression before 
‘if’

/usr/include/c++/4.4/bits/stl_algobase.h:256: error: expected ‘}’ before ‘if’

/usr/include/c++/4.4/bits/stl_algobase.h:258: error: expected unqualified-id before 
‘return’

/usr/include/c++/4.4/bits/stl_algobase.h:259: error: expected declaration before ‘}’ token


make[1]: *** [sysdep.o] Error 1

make[1]: Leaving directory `/home/f85/njvanbal/workspace/nachos2/userprog'

make: *** [all] Error 2
+1  A: 

Always best to look back to the first error first; in your case:

/usr/include/c++/4.4/bits/stl_algobase.h:232:56: error: macro "min" passed 3 arguments, 
but takes just 2
/usr/include/c++/4.4/bits/stl_algobase.h:253:56: error: macro "max" passed 3 arguments, 
but takes just 2

Looks like you have defined a macro (or maybe a function) called min and max in your own code. The #include for vector apparently also defines a macro for min and max and the compiler is getting confused. Change the name of your min and max macros.

greg
@user381261: Macros are evil. You had obviously heard about that. Now you have a proof. If you have to use macros, just name them WITH_LONG_UGLY_NAMES so as to minimize the possibility that they had been defined elsewere. Namespaces won't help inasmuch as macros don't obey scope... Why don't people just blindly follow good advice like "don't use macros unless you have to"
Armen Tsirunyan
I didn't write the project and I'm not allowed to modify the code where those macros are, but I'll make sure to keep in mind your suggestions in the future.
Somebody wrote macros calles `min` and `max`, and put them in headers you're not allowed to modify? This is worthy of thedailywtf.com.
Beta
Come to think of it, you could `#define min min` and `#define max max` in your own code, somewhere after their headers-- just make sure it's not in something other people must `#include`.
Beta