* C++ help, please? (fwd)
@ 1999-02-16 7:40 H.J. Lu
[not found] ` < m10Cmc0-000392C@ocean.lucon.org >
1999-02-28 22:53 ` H.J. Lu
0 siblings, 2 replies; 6+ messages in thread
From: H.J. Lu @ 1999-02-16 7:40 UTC (permalink / raw)
To: egcs
Hi,
I got this. Is this an egcs bug or is the code bogus?
Thanks.
H.J.
---
I'm having a weird trouble with egcs-1.1.1 using STL stuff.
It may well be that I'm doing something wrong - but maybe
you can spot it, as I can't. I spent the whole last night
trying to figure out what the f*** is wrong with the code
I've written - to no avail. If you could shed ANY light
on my problem(s), I'd he happy! Thank you!
Here's the code:
#include <hash_map>
typedef const unsigned char ByteKeyID[8];
struct kcmp {
bool operator() (ByteKeyID a, ByteKeyID b) const {
return (memcmp(a, b, 8) == 0);
}
};
typedef hash_map<ByteKeyID,
int,
hash<ByteKeyID>,
kcmp>
hmap;
int main(int argc, char **argv)
{
int i=0;
ByteKeyID kid;
hmap hm;
for (i = 0; i < 8; i++) kid[i] = 8-i;
hm.insert(kid, 2);
for (i = 0; i < 8; i++) kid[i] = i;
hm.insert(kid, 10);
for (i = 0; i < 8; i++) kid[i] = 8-i;
cout << "Extracted first value: ";
cout << hm[kid] << endl;
}
Here's what the compiler says:
uri@alisan:/usr2/src/crypto-3.0 > g++ -I. -g -o v2-t v2-t.cc
/usr/include/g++-2/stl_hash_map.h: In instantiation of `hash_map<const unsigned char[8],int,hash<const unsigned char[8]>,kcmp,__default_alloc_template<false,0> >::hash_map<unsigned char[8], int, hash<const unsigned char[8]>, kcmp, alloc>()':
v2-t.cc:21: instantiated from here
/usr/include/g++-2/stl_hash_map.h:78: new declaration `hash_map<unsigned char[8],int,hash<const unsigned char[8]>,kcmp,__default_alloc_template<false,0> >::hash_map<>()'
/usr/include/g++-2/stl_hash_map.h:78: ambiguates old declaration `hash_map<const unsigned char[8],int,hash<const unsigned char[8]>,kcmp,__default_alloc_template<false,0> >::hash_map<unsigned char[8], int, hash<const unsigned char[8]>, kcmp, alloc>()'
/usr/include/g++-2/stl_hash_map.h: In method `hash_map<const unsigned char[8],int,hash<const unsigned char[8]>,kcmp,__default_alloc_template<false,0> >::hash_map<unsigned char[8], int, hash<const unsigned char[8]>, kcmp, alloc>()':
/usr/include/g++-2/stl_hash_map.h:78: confused by earlier errors, bailing out
uri@alisan:/usr2/src/crypto-3.0 > g++ -v
Reading specs from /usr/lib/gcc-lib/i586-pc-linux-gnulibc1/egcs-2.91.60.1/specs
gcc version egcs-2.91.60.1 19990115/Linux (egcs-1.1.1 release)
uri@alisan:/usr2/src/crypto-3.0 >
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: C++ help, please? (fwd)
[not found] ` < m10Cmc0-000392C@ocean.lucon.org >
@ 1999-02-16 8:28 ` Paul Derbyshire
1999-02-28 22:53 ` Paul Derbyshire
1999-02-16 15:26 ` Joe Buck
1 sibling, 1 reply; 6+ messages in thread
From: Paul Derbyshire @ 1999-02-16 8:28 UTC (permalink / raw)
To: egcs
At 07:40 AM 2/16/99 -0800, H.J. Lu wrote:
>Hi,
>
>I got this. Is this an egcs bug or is the code bogus?
[deletia]
That's damned strange. The problem *appears* to be being caused by 'const'
modifiers mysteriously disappearing from your typedef'd array in the
default constructor's *template* arguments.
I'd guess it's an EGCS bug.
--
.*. "Clouds are not spheres, mountains are not cones, coastlines are not
-() < circles, and bark is not smooth, nor does lightning travel in a
`*' straight line." -------------------------------------------------
-- B. Mandelbrot | http://surf.to/pgd.net
_____________________ ____|________ Paul Derbyshire pderbysh@usa.net
Programmer & Humanist|ICQ: 10423848|
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: C++ help, please? (fwd)
[not found] ` < m10Cmc0-000392C@ocean.lucon.org >
1999-02-16 8:28 ` Paul Derbyshire
@ 1999-02-16 15:26 ` Joe Buck
1999-02-28 22:53 ` Joe Buck
1 sibling, 1 reply; 6+ messages in thread
From: Joe Buck @ 1999-02-16 15:26 UTC (permalink / raw)
To: H.J. Lu; +Cc: egcs
> I got this. Is this an egcs bug or is the code bogus?
In the future please ask people to use gnu.g++.help for these.
The code is extremely bogus, however egcs-1.1.1 gets messed up by it.
The current snapshot compiler gives much better diagnostics, so it
doesn't look like we have remaining bugs.
Bogosities in the code:
1. attempt to write to a const object: note
typedef const unsigned char ByteKeyID[8];
the user then writes
ByteKeyID kid;
and proceeds to assign to its elements.
2. wrong interface to 'insert' function. There is no insert(key,value)
interface. The user could write
hm[key] = value;
which is easy to write and to understand. insert takes a pair.
3. hash<T> specializations are only provided for certain types,
and arrays of 8 unsigned chars are not among them. The user must
supply a hash function.
4. The user appears to be counting on being able to pass arrays by value.
One way to do this safely is to wrap the array in a struct:
struct ByteKeyID {
unsigned char data[8];
};
but it simply won't work otherwise.
> ...
> Here's the code:
>
> #include <hash_map>
>
> typedef const unsigned char ByteKeyID[8];
>
> struct kcmp {
> bool operator() (ByteKeyID a, ByteKeyID b) const {
> return (memcmp(a, b, 8) == 0);
> }
> };
>
> typedef hash_map<ByteKeyID,
> int,
> hash<ByteKeyID>,
> kcmp>
> hmap;
>
> int main(int argc, char **argv)
> {
> int i=0;
> ByteKeyID kid;
> hmap hm;
>
> for (i = 0; i < 8; i++) kid[i] = 8-i;
> hm.insert(kid, 2);
>
> for (i = 0; i < 8; i++) kid[i] = i;
> hm.insert(kid, 10);
>
> for (i = 0; i < 8; i++) kid[i] = 8-i;
>
> cout << "Extracted first value: ";
> cout << hm[kid] << endl;
> }
>
> Here's what the compiler says:
>
> uri@alisan:/usr2/src/crypto-3.0 > g++ -I. -g -o v2-t v2-t.cc
> /usr/include/g++-2/stl_hash_map.h: In instantiation of `hash_map<const unsigned char[8],int,hash<const unsigned char[8]>,kcmp,__default_alloc_template<false,0> >::hash_map<unsigned char[8], int, hash<const unsigned char[8]>, kcmp, alloc>()':
> v2-t.cc:21: instantiated from here
> /usr/include/g++-2/stl_hash_map.h:78: new declaration `hash_map<unsigned char[8],int,hash<const unsigned char[8]>,kcmp,__default_alloc_template<false,0> >::hash_map<>()'
> /usr/include/g++-2/stl_hash_map.h:78: ambiguates old declaration `hash_map<const unsigned char[8],int,hash<const unsigned char[8]>,kcmp,__default_alloc_template<false,0> >::hash_map<unsigned char[8], int, hash<const unsigned char[8]>, kcmp, alloc>()'
> /usr/include/g++-2/stl_hash_map.h: In method `hash_map<const unsigned char[8],int,hash<const unsigned char[8]>,kcmp,__default_alloc_template<false,0> >::hash_map<unsigned char[8], int, hash<const unsigned char[8]>, kcmp, alloc>()':
> /usr/include/g++-2/stl_hash_map.h:78: confused by earlier errors, bailing out
> uri@alisan:/usr2/src/crypto-3.0 > g++ -v
> Reading specs from /usr/lib/gcc-lib/i586-pc-linux-gnulibc1/egcs-2.91.60.1/specs
> gcc version egcs-2.91.60.1 19990115/Linux (egcs-1.1.1 release)
> uri@alisan:/usr2/src/crypto-3.0 >
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* C++ help, please? (fwd)
1999-02-16 7:40 C++ help, please? (fwd) H.J. Lu
[not found] ` < m10Cmc0-000392C@ocean.lucon.org >
@ 1999-02-28 22:53 ` H.J. Lu
1 sibling, 0 replies; 6+ messages in thread
From: H.J. Lu @ 1999-02-28 22:53 UTC (permalink / raw)
To: egcs
Hi,
I got this. Is this an egcs bug or is the code bogus?
Thanks.
H.J.
---
I'm having a weird trouble with egcs-1.1.1 using STL stuff.
It may well be that I'm doing something wrong - but maybe
you can spot it, as I can't. I spent the whole last night
trying to figure out what the f*** is wrong with the code
I've written - to no avail. If you could shed ANY light
on my problem(s), I'd he happy! Thank you!
Here's the code:
#include <hash_map>
typedef const unsigned char ByteKeyID[8];
struct kcmp {
bool operator() (ByteKeyID a, ByteKeyID b) const {
return (memcmp(a, b, 8) == 0);
}
};
typedef hash_map<ByteKeyID,
int,
hash<ByteKeyID>,
kcmp>
hmap;
int main(int argc, char **argv)
{
int i=0;
ByteKeyID kid;
hmap hm;
for (i = 0; i < 8; i++) kid[i] = 8-i;
hm.insert(kid, 2);
for (i = 0; i < 8; i++) kid[i] = i;
hm.insert(kid, 10);
for (i = 0; i < 8; i++) kid[i] = 8-i;
cout << "Extracted first value: ";
cout << hm[kid] << endl;
}
Here's what the compiler says:
uri@alisan:/usr2/src/crypto-3.0 > g++ -I. -g -o v2-t v2-t.cc
/usr/include/g++-2/stl_hash_map.h: In instantiation of `hash_map<const unsigned char[8],int,hash<const unsigned char[8]>,kcmp,__default_alloc_template<false,0> >::hash_map<unsigned char[8], int, hash<const unsigned char[8]>, kcmp, alloc>()':
v2-t.cc:21: instantiated from here
/usr/include/g++-2/stl_hash_map.h:78: new declaration `hash_map<unsigned char[8],int,hash<const unsigned char[8]>,kcmp,__default_alloc_template<false,0> >::hash_map<>()'
/usr/include/g++-2/stl_hash_map.h:78: ambiguates old declaration `hash_map<const unsigned char[8],int,hash<const unsigned char[8]>,kcmp,__default_alloc_template<false,0> >::hash_map<unsigned char[8], int, hash<const unsigned char[8]>, kcmp, alloc>()'
/usr/include/g++-2/stl_hash_map.h: In method `hash_map<const unsigned char[8],int,hash<const unsigned char[8]>,kcmp,__default_alloc_template<false,0> >::hash_map<unsigned char[8], int, hash<const unsigned char[8]>, kcmp, alloc>()':
/usr/include/g++-2/stl_hash_map.h:78: confused by earlier errors, bailing out
uri@alisan:/usr2/src/crypto-3.0 > g++ -v
Reading specs from /usr/lib/gcc-lib/i586-pc-linux-gnulibc1/egcs-2.91.60.1/specs
gcc version egcs-2.91.60.1 19990115/Linux (egcs-1.1.1 release)
uri@alisan:/usr2/src/crypto-3.0 >
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: C++ help, please? (fwd)
1999-02-16 8:28 ` Paul Derbyshire
@ 1999-02-28 22:53 ` Paul Derbyshire
0 siblings, 0 replies; 6+ messages in thread
From: Paul Derbyshire @ 1999-02-28 22:53 UTC (permalink / raw)
To: egcs
At 07:40 AM 2/16/99 -0800, H.J. Lu wrote:
>Hi,
>
>I got this. Is this an egcs bug or is the code bogus?
[deletia]
That's damned strange. The problem *appears* to be being caused by 'const'
modifiers mysteriously disappearing from your typedef'd array in the
default constructor's *template* arguments.
I'd guess it's an EGCS bug.
--
.*. "Clouds are not spheres, mountains are not cones, coastlines are not
-() < circles, and bark is not smooth, nor does lightning travel in a
`*' straight line." -------------------------------------------------
-- B. Mandelbrot | http://surf.to/pgd.net
_____________________ ____|________ Paul Derbyshire pderbysh@usa.net
Programmer & Humanist|ICQ: 10423848|
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: C++ help, please? (fwd)
1999-02-16 15:26 ` Joe Buck
@ 1999-02-28 22:53 ` Joe Buck
0 siblings, 0 replies; 6+ messages in thread
From: Joe Buck @ 1999-02-28 22:53 UTC (permalink / raw)
To: H.J. Lu; +Cc: egcs
> I got this. Is this an egcs bug or is the code bogus?
In the future please ask people to use gnu.g++.help for these.
The code is extremely bogus, however egcs-1.1.1 gets messed up by it.
The current snapshot compiler gives much better diagnostics, so it
doesn't look like we have remaining bugs.
Bogosities in the code:
1. attempt to write to a const object: note
typedef const unsigned char ByteKeyID[8];
the user then writes
ByteKeyID kid;
and proceeds to assign to its elements.
2. wrong interface to 'insert' function. There is no insert(key,value)
interface. The user could write
hm[key] = value;
which is easy to write and to understand. insert takes a pair.
3. hash<T> specializations are only provided for certain types,
and arrays of 8 unsigned chars are not among them. The user must
supply a hash function.
4. The user appears to be counting on being able to pass arrays by value.
One way to do this safely is to wrap the array in a struct:
struct ByteKeyID {
unsigned char data[8];
};
but it simply won't work otherwise.
> ...
> Here's the code:
>
> #include <hash_map>
>
> typedef const unsigned char ByteKeyID[8];
>
> struct kcmp {
> bool operator() (ByteKeyID a, ByteKeyID b) const {
> return (memcmp(a, b, 8) == 0);
> }
> };
>
> typedef hash_map<ByteKeyID,
> int,
> hash<ByteKeyID>,
> kcmp>
> hmap;
>
> int main(int argc, char **argv)
> {
> int i=0;
> ByteKeyID kid;
> hmap hm;
>
> for (i = 0; i < 8; i++) kid[i] = 8-i;
> hm.insert(kid, 2);
>
> for (i = 0; i < 8; i++) kid[i] = i;
> hm.insert(kid, 10);
>
> for (i = 0; i < 8; i++) kid[i] = 8-i;
>
> cout << "Extracted first value: ";
> cout << hm[kid] << endl;
> }
>
> Here's what the compiler says:
>
> uri@alisan:/usr2/src/crypto-3.0 > g++ -I. -g -o v2-t v2-t.cc
> /usr/include/g++-2/stl_hash_map.h: In instantiation of `hash_map<const unsigned char[8],int,hash<const unsigned char[8]>,kcmp,__default_alloc_template<false,0> >::hash_map<unsigned char[8], int, hash<const unsigned char[8]>, kcmp, alloc>()':
> v2-t.cc:21: instantiated from here
> /usr/include/g++-2/stl_hash_map.h:78: new declaration `hash_map<unsigned char[8],int,hash<const unsigned char[8]>,kcmp,__default_alloc_template<false,0> >::hash_map<>()'
> /usr/include/g++-2/stl_hash_map.h:78: ambiguates old declaration `hash_map<const unsigned char[8],int,hash<const unsigned char[8]>,kcmp,__default_alloc_template<false,0> >::hash_map<unsigned char[8], int, hash<const unsigned char[8]>, kcmp, alloc>()'
> /usr/include/g++-2/stl_hash_map.h: In method `hash_map<const unsigned char[8],int,hash<const unsigned char[8]>,kcmp,__default_alloc_template<false,0> >::hash_map<unsigned char[8], int, hash<const unsigned char[8]>, kcmp, alloc>()':
> /usr/include/g++-2/stl_hash_map.h:78: confused by earlier errors, bailing out
> uri@alisan:/usr2/src/crypto-3.0 > g++ -v
> Reading specs from /usr/lib/gcc-lib/i586-pc-linux-gnulibc1/egcs-2.91.60.1/specs
> gcc version egcs-2.91.60.1 19990115/Linux (egcs-1.1.1 release)
> uri@alisan:/usr2/src/crypto-3.0 >
>
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~1999-02-28 22:53 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-02-16 7:40 C++ help, please? (fwd) H.J. Lu
[not found] ` < m10Cmc0-000392C@ocean.lucon.org >
1999-02-16 8:28 ` Paul Derbyshire
1999-02-28 22:53 ` Paul Derbyshire
1999-02-16 15:26 ` Joe Buck
1999-02-28 22:53 ` Joe Buck
1999-02-28 22:53 ` H.J. Lu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).