tags:

views:

99

answers:

3

The following code tests the use of std::map with std::string as a key:

#include <stdio.h>
#include <map>
#include <string>
using namespace std;

typedef map<string, int> test_map_t;

int main(int argc, char **argv) {
    test_map_t test_map;

    test_map["test1"]= 1;    
    test_map["test2"]= 2;
    test_map["test3"]= 3;    

    string tmp= "test1";
    printf("%s : %d \n", tmp.c_str(), test_map[tmp]);

    return 0;
}

When compiled with ordinary gcc, this test will print out "test1 : 1", as expected. However, when compiled with alchemy it will print "test1 : 3" (!). Something is very wrong here.

Are there any workarounds for this or am I just stuck?

+1  A: 

Sure looks like a bug.

Typically the source code (headers) is part of STL distribution - can you step thru to find out what is going on? Compare source to GCC version maybe.

Seems like you have a cast-iron case to take this to the vendor for fix if confirmed.

Steve Townsend
A: 

Should not you use cstdio? But your code works perfectly with gcc version 4.4.2 20091027, i have tested it. Is it the complete code or something is there which might be overwriting the stack.

#include <cstdio>
#include <map>
yadab
`<stdio.h>` can be used and since the OP uses `using namespace std;`, there wouldn't really be much difference between the two.
James McNellis
+2  A: 

class string is broken in alchemy. There is a bug in operator copy (=). map works fine with other class

babyshambles
how can anyone fuck up string::operator= ...
Viktor Sehr
(hmm probably because someone is trying to be smart with hash-values)
Viktor Sehr
Right after you posted this answer, someone answered on the alchemy forums also: http://forums.adobe.com/thread/725089?tstart=0
paleozogt
I ended up working around this problem by making the map use const char*. (Fortunately for me the keys don't need to be added dynamically.)
paleozogt
+1 Thanks. I knew there was something funny with strings in Alchemy, but I could never narrow it down.
Gunslinger47