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?

paleozogt
  • 6,393
  • 11
  • 51
  • 94

3 Answers3

2

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

  • (hmm probably because someone is trying to be smart with hash-values) – Viktor Sehr Sep 24 '10 at 08:30
  • Right after you posted this answer, someone answered on the alchemy forums also: http://forums.adobe.com/thread/725089?tstart=0 – paleozogt Sep 24 '10 at 15:00
  • 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 Sep 24 '10 at 15:01
  • +1 Thanks. I knew there was something funny with strings in Alchemy, but I could never narrow it down. – Gunslinger47 Sep 25 '10 at 08:50
  • I figured out a fix to the std::string problem. See this [SO post](http://stackoverflow.com/questions/7421832/using-stl-with-alchemy/) – paleozogt Sep 20 '11 at 18:16
1

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
  • 53,498
  • 9
  • 91
  • 140
0

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
  • 2,063
  • 1
  • 16
  • 24