• Welcome to Valhalla Legends Archive.
 

GCC w/ Templates

Started by Mephisto, April 28, 2004, 03:46 PM

Previous topic - Next topic

Mephisto

Assuming Dev-CPP is in fact an IDE which uses a GCC compiler, is it just me or does GCC fail to process templates and STL containers correctly at runtime?  For instance, you write code which should do this and that and then it ends up not doing it right, or not doing it at all...Has anyone else had similar problems using GCC?  Also, what's more interesting is that the same exact code works just as expected in Microsoft's compiler (I haven't tested any others).  Also, this is Win32-platform.

Adron

Show some code. Post the simplest possible example that produces the effects you describe. Tell us what happens and what you believe should have happened.

Mephisto

It may be my fault, but I did remember Kp bringing something about GCC getting *stupid* when it came to processing templates at runtime and getting confused and doing the wrong thing.  So I decided to bring this up since I was experiencing a problem myself.

Here's the code which I posted as a solution to another post someone made.  It's suppose to have you enter 10 numbers and insert them into the set for each loop cycle.  Then after entering 10 numbers the loop breaks, then it's suppose to iterate through the set and print the inserted values one at a time least to greatest as that's how a set works.  Well, when compiled in GCC it goes through the first loop, then it fails in the second loop, though I suspect it fails in the first loop in inserting the values into the set.  On Microsoft's compiler, it does as expected and prints out the numbers from least to greatest after entering them in from the first loop.


#include <iostream>
#include <set>
int main() {

   typedef std::set<int> ISet;
   ISet num;
   
   for (int i = 0, temp; i < 10 && std::cin >> temp; ++i) {
       num.insert(temp);
   }
   
   ISet::const_iterator it;
   
   for (it = num.begin(); it != num.end(); ++it) {
       std::cout << *it << ' ';
   }
   
   std::cout << std::endl;
   return 0;
}

Adron

That code worked fine with gcc 2.96 here.

Mephisto

Interesting.  It fails in Dev-CPP.