This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Is this normal behavior or an error [libstdc++/has_map]


Hello gcc-bugs-fellas,

Following Sourcecode:

#include <ext/hash_map>
#include <string>
#include <iostream>

int main(){
        __gnu_cxx::hash_map<const char *, int> testmap;
        __gnu_cxx::hash<const char *> Hash;
        std::string dummy;

        testmap["test"]=7;
        std::cout << "Output of testmap[\"test\"]: " << testmap["test"] << std::endl;
        dummy="test";
        std::cout << "Output of testmap[dummy.c_str()]: " << testmap[dummy.c_str()] << std::endl;
        std::cout << "Hash(\"test\"): " << Hash("test") << std::endl;
        std::cout << "Hash(dummy.c_str(): " << Hash(dummy.c_str()) << std::endl;

        return 0;
}

Yields:

Output of testmap["test"]: 7
Output of testmap[dummy.c_str()]: 0
Hash("test"): 17716
Hash(dummy.c_str(): 17716

As one can see, and as I would assume, the hash value is identical.
But why das testmap[dummy.c_Str()] yield 0 instead of 7 ?

Both char 'arrays' have the same content and I'd assume, that they get
hashed into the same bucket and the keys should match.

Is that behavior as I can see it totally normal, or is it a bug ?
Sorry if I picked the wrong list, I wasn'T sure if libstdc++ is part
of the gcc distribution.

gcc -v
Reading specs from /usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.3/specs
Configured with: /var/tmp/portage/gcc-3.3.3-r6/work/gcc-3.3.3/configure
--prefix=/usr --bindir=/usr/i686-pc-linux-gnu/gcc-bin/3.3
--includedir=/usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.3/include
--datadir=/usr/share/gcc-data/i686-pc-linux-gnu/3.3
--mandir=/usr/share/gcc-data/i686-pc-linux-gnu/3.3/man
--infodir=/usr/share/gcc-data/i686-pc-linux-gnu/3.3/info --enable-shared
--host=i686-pc-linux-gnu --target=i686-pc-linux-gnu --with-system-zlib
--enable-languages=c,c++ --enable-threads=posix --enable-long-long --disable-checking
--disable-libunwind-exceptions --enable-cstdio=stdio
--enable-version-specific-runtime-libs
--with-gxx-include-dir=/usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.3/include/g++-v3
--with-local-prefix=/usr/local --enable-shared --enable-nls --without-included-gettext
--disable-multilib --enable-__cxa_atexit --enable-clocale=generic
Thread model: posix
gcc version 3.3.3 20040412 (Gentoo Linux 3.3.3-r6, ssp-3.3.2-2, pie-8.7.6)

If any further Data is needed, please don't hesitate and tell me what
is needed

P.S.: I could bind anything in the bugs database or FAQ, but maybe I
just didn't look well enough ?

-- 
With best regards,
 Sven Eschenberg                       mailto:eschenb@cs.uni-frankfurt.de


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]