FW: [omniORB] Compiler warnings (casting from const char* to
char * and vice versa)
Matej Kenda
matej.kenda@hermes.si
Thu, 31 Jan 2002 14:55:01 +0100
This message is in MIME format. Since your mail reader does not understand
this format, some or all of this message may not be legible.
------_=_NextPart_000_01C1AA5E.E0644540
Content-Type: text/plain
OK. The patch (unified diff) file for omniORB3 is attached.
Matej
-----Original Message-----
From: Duncan Grisby [mailto:dgrisby@uk.research.att.com]
Sent: Tuesday, January 29, 2002 12:02 PM
To: Matej Kenda
Subject: Re: FW: [omniORB] Compiler warnings (casting from const char* to
char * and vice versa)
On Wednesday 23 January, Matej Kenda wrote:
> I have sent omniORB3 header changes to the mailing list, but it seems
> that it failed to get there.
Please can you send the changes as a unified diff, rather than just the
changed files? It's rather hard to deal with the changed files, since other
things have changed.
Thanks,
Duncan.
--
-- Duncan Grisby \ Research Engineer --
-- AT&T Laboratories Cambridge --
-- http://www.uk.research.att.com/~dpg1 --
------_=_NextPart_000_01C1AA5E.E0644540
Content-Type: application/octet-stream;
name="cpp_cast.patch"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
filename="cpp_cast.patch"
diff -B --unified -r include/omniORB3/CORBA.h =
includefx/omniORB3/CORBA.h=0A=
--- include/omniORB3/CORBA.h Thu Jan 31 14:27:13 2002=0A=
+++ includefx/omniORB3/CORBA.h Thu Jan 31 14:32:42 2002=0A=
@@ -423,7 +423,11 @@=0A=
=0A=
struct from_string {=0A=
from_string(const char* s, ULong b, Boolean nocopy =3D 0)=0A=
+#if HAS_CPP_CAST=0A=
+ : val(const_cast<char*>(s)), bound(b), nc(nocopy) { }=0A=
+#else=0A=
: val((char*)s), bound(b), nc(nocopy) { }=0A=
+#endif=0A=
from_string(char* s, ULong b, Boolean nocopy =3D 0)=0A=
: val(s), bound(b), nc(nocopy) { } // deprecated=0A=
=0A=
diff -B --unified -r include/omniORB3/stringtypes.h =
includefx/omniORB3/stringtypes.h=0A=
--- include/omniORB3/stringtypes.h Thu Jan 31 14:27:13 2002=0A=
+++ includefx/omniORB3/stringtypes.h Thu Jan 31 14:33:12 2002=0A=
@@ -182,15 +182,46 @@=0A=
//////////////////////////// String_member =
///////////////////////////=0A=
=
//////////////////////////////////////////////////////////////////////=0A=
=0A=
+// Check if compiler supports C++ casting=0A=
+=0A=
+// Visual C++ version check: _MSC_VER >=3D 1100 (VC++ 5.0)=0A=
+=0A=
+// __GNUC__ gcc major version (1, 2, 3)=0A=
+// __GNUC_MINOR__ gcc minor version (.95)=0A=
+=0A=
+// =0A=
+#ifdef __GNUC__=0A=
+ // GNU Compiler version 2.95 or newer=0A=
+ #if (__GNUC__ >=3D 3) || ( (__GNUC__ =3D=3D 2) && (__GNUC_MINOR__ =
>=3D 95))=0A=
+ #define HAS_CPP_CAST (1)=0A=
+ #endif=0A=
+#endif=0A=
+=0A=
+#ifdef _MSC_VER=0A=
+ // MS Compiler version 11.00 (Visual C++ 5.0) or newer=0A=
+ #if (_MSC_VER >=3D 1100)=0A=
+ #define HAS_CPP_CAST (1)=0A=
+ #endif=0A=
+#endif=0A=
+=0A=
+=0A=
class _CORBA_String_member {=0A=
public:=0A=
typedef char* ptr_t;=0A=
=0A=
inline _CORBA_String_member()=0A=
+#if HAS_CPP_CAST=0A=
+ : _ptr(const_cast<char*>(omni::empty_string)) {}=0A=
+#else=0A=
: _ptr((char*) omni::empty_string) {}=0A=
+#endif=0A=
=0A=
inline _CORBA_String_member(const _CORBA_String_member& s) =0A=
+#if HAS_CPP_CAST=0A=
+ : _ptr(const_cast<char*>(omni::empty_string)) {=0A=
+#else=0A=
: _ptr((char*)omni::empty_string) {=0A=
+#endif=0A=
if (s._ptr && s._ptr !=3D omni::empty_string)=0A=
_ptr =3D _CORBA_String_var::string_dup(s._ptr);=0A=
}=0A=
@@ -319,7 +350,11 @@=0A=
else=0A=
pd_data =3D 0;=0A=
} else {=0A=
+#if HAS_CPP_CAST=0A=
+ pd_data =3D const_cast<char*>(s);=0A=
+#else=0A=
pd_data =3D (char*)s;=0A=
+#endif=0A=
}=0A=
return *this;=0A=
}=0A=
@@ -346,7 +381,11 @@=0A=
else=0A=
pd_data =3D 0;=0A=
} else=0A=
+#if HAS_CPP_CAST=0A=
+ pd_data =3D const_cast<char*>((const char*)s);=0A=
+#else=0A=
pd_data =3D (char*)(const char*)s;=0A=
+#endif=0A=
return *this;=0A=
}=0A=
=0A=
@@ -356,9 +395,17 @@=0A=
if( (const char*)s && (const char*) s !=3D =
omni::empty_string)=0A=
pd_data =3D _CORBA_String_var::string_dup((const char*)s);=0A=
else=0A=
- pd_data =3D (char*)(const char*)s;=0A=
+#if HAS_CPP_CAST=0A=
+ pd_data =3D const_cast<char*>((const char*)s);=0A=
+#else=0A=
+ pd_data =3D (char*)(const char*)s;=0A=
+#endif=0A=
} else=0A=
+#if HAS_CPP_CAST=0A=
+ pd_data =3D const_cast<char*>((const char*)s);=0A=
+#else=0A=
pd_data =3D (char*)(const char*)s;=0A=
+#endif=0A=
return *this;=0A=
}=0A=
=0A=
@@ -559,7 +606,11 @@=0A=
=0A=
// If we've shrunk we need to clear the entries at the top.=0A=
for( _CORBA_ULong i =3D len; i < pd_len; i++ ) =0A=
+#if HAS_CPP_CAST=0A=
+ operator[](i) =3D const_cast<char*>(omni::empty_string);=0A=
+#else=0A=
operator[](i) =3D (char*) omni::empty_string;=0A=
+#endif=0A=
=0A=
if (len) {=0A=
// Allocate buffer on-demand. Either pd_data =3D=3D 0 =0A=
@@ -587,7 +638,11 @@=0A=
b[0] =3D (char*) ((omni::ptr_arith_t) 0x53515354U);=0A=
b[1] =3D (char*) l;=0A=
for (_CORBA_ULong index =3D 2; index < (nelems+2); index++)=0A=
+#if HAS_CPP_CAST=0A=
+ b[index] =3D const_cast<char*>(omni::empty_string);=0A=
+#else=0A=
b[index] =3D (char*)omni::empty_string;=0A=
+#endif=0A=
return b+2;=0A=
}=0A=
=0A=
------_=_NextPart_000_01C1AA5E.E0644540--