hyc@OpenLDAP.org writes:
lber_pvt.h 1.39 -> 1.40 Silence BER_BVC warning
-#define BER_BVC(s) { STRLENOF(s), (s) } +#define BER_BVC(s) { STRLENOF(s), (char *)(s) }
Is this a "cast away const"? It also removes warnings about genuine type errors.
If it's just for a few cases, how about adding a BER_BVCC macro which takes a const char[] instead? Or if it's for C++, that can use const_cast<char *>(s).
Hallvard B Furuseth wrote:
hyc@OpenLDAP.org writes:
lber_pvt.h 1.39 -> 1.40 Silence BER_BVC warning
-#define BER_BVC(s) { STRLENOF(s), (s) } +#define BER_BVC(s) { STRLENOF(s), (char *)(s) }
Is this a "cast away const"?
Yes.
It also removes warnings about genuine type errors.
If it's just for a few cases, how about adding a BER_BVCC macro which takes a const char[] instead? Or if it's for C++, that can use const_cast<char *>(s).
OK, either of those would be fine if you want to revert this checkin. Though we shouldn't use any C++ syntax in these headers.
Howard Chu writes:
(...)
Silence BER_BVC warning -#define BER_BVC(s) { STRLENOF(s), (s) } +#define BER_BVC(s) { STRLENOF(s), (char *)(s) } (...)
If it's just for a few cases, how about adding a BER_BVCC macro which takes a const char[] instead? Or if it's for C++, that can use const_cast<char *>(s).
OK, either of those would be fine if you want to revert this checkin. Though we shouldn't use any C++ syntax in these headers.
I'll add BVCC then. And use it - where? I don't get any warnings. In fact I just tried #define BER_BVC(s) { STRLENOF(s), ("" s "") } #define BER_BVSTR(bv,s) ... (bv)->bv_val = ("" s ""); ... which requires s to be a string constant, and only got one error back-bdb/index.c:presence_key.
Maybe we should do that as well #if __STDC__? It gives an error if one casts away const on s, which changes the result of STRLENOF().
Hallvard B Furuseth wrote:
Howard Chu writes:
(...)
Silence BER_BVC warning -#define BER_BVC(s) { STRLENOF(s), (s) } +#define BER_BVC(s) { STRLENOF(s), (char *)(s) } (...)
If it's just for a few cases, how about adding a BER_BVCC macro which takes a const char[] instead? Or if it's for C++, that can use const_cast<char *>(s).
OK, either of those would be fine if you want to revert this checkin. Though we shouldn't use any C++ syntax in these headers.
I'll add BVCC then. And use it - where? I don't get any warnings.
I'm only getting warnings from g++. ../../../servers/slapd/back-ndb/init.cpp:40: warning: deprecated conversion from string constant to 'char*'
In fact I just tried #define BER_BVC(s) { STRLENOF(s), ("" s "") } #define BER_BVSTR(bv,s) ... (bv)->bv_val = ("" s ""); ... which requires s to be a string constant, and only got one error back-bdb/index.c:presence_key.
Maybe we should do that as well #if __STDC__? It gives an error if one casts away const on s, which changes the result of STRLENOF().
I'm thinking your original concern is a non-issue. BER_BVC is only intended for use with string constants in the first place, and STRLENOF() will be wrong for non-constants.
Howard Chu writes:
I'm only getting warnings from g++. ../../../servers/slapd/back-ndb/init.cpp:40: warning: deprecated conversion from string constant to 'char*'
In fact I just tried #define BER_BVC(s) { STRLENOF(s), ("" s "") } #define BER_BVSTR(bv,s) ... (bv)->bv_val = ("" s ""); ... which requires s to be a string constant, and only got one error back-bdb/index.c:presence_key.
Maybe we should do that as well #if __STDC__? It gives an error if one casts away const on s, which changes the result of STRLENOF().
I'm thinking your original concern is a non-issue. BER_BVC is only intended for use with string constants in the first place,
After changing my mind a few times, I agree:-) A type error looks less likely than than BER_BVC(<char* variable>), an error the original version did not catch.
and STRLENOF() will be wrong for non-constants.
Well, it works for char[] = "foo" variables. Except for that, the hack I quoted above kind of grew on me.