[prev in list] [next in list] [prev in thread] [next in thread] 

List:       omniorb-list
Subject:    RE: FW: [omniORB] Compiler warnings (casting from const char* to
From:       Matej Kenda <matej.kenda () hermes ! si>
Date:       2002-01-31 13:55:01
[Download RAW message or body]

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 --


["cpp_cast.patch" (application/octet-stream)]

diff -B --unified -r include/omniORB3/CORBA.h includefx/omniORB3/CORBA.h
--- include/omniORB3/CORBA.h	Thu Jan 31 14:27:13 2002
+++ includefx/omniORB3/CORBA.h	Thu Jan 31 14:32:42 2002
@@ -423,7 +423,11 @@
 
     struct from_string {
       from_string(const char* s, ULong b, Boolean nocopy = 0)
+#if HAS_CPP_CAST
+	: val(const_cast<char*>(s)), bound(b), nc(nocopy) { }
+#else
 	: val((char*)s), bound(b), nc(nocopy) { }
+#endif
       from_string(char* s, ULong b, Boolean nocopy = 0)
 	: val(s), bound(b), nc(nocopy) { }   // deprecated
 
diff -B --unified -r include/omniORB3/stringtypes.h includefx/omniORB3/stringtypes.h
--- include/omniORB3/stringtypes.h	Thu Jan 31 14:27:13 2002
+++ includefx/omniORB3/stringtypes.h	Thu Jan 31 14:33:12 2002
@@ -182,15 +182,46 @@
 //////////////////////////// String_member ///////////////////////////
 //////////////////////////////////////////////////////////////////////
 
+// Check if compiler supports C++ casting
+
+// Visual C++ version check: _MSC_VER >= 1100 (VC++ 5.0)
+
+// __GNUC__ gcc major version (1, 2, 3)
+// __GNUC_MINOR__ gcc minor version (.95)
+
+// 
+#ifdef __GNUC__
+    // GNU Compiler version 2.95 or newer
+    #if (__GNUC__ >= 3) || ( (__GNUC__ == 2) && (__GNUC_MINOR__ >= 95))
+        #define HAS_CPP_CAST  (1)
+    #endif
+#endif
+
+#ifdef _MSC_VER
+    // MS Compiler version 11.00 (Visual C++ 5.0)  or newer
+    #if (_MSC_VER >= 1100)
+        #define HAS_CPP_CAST  (1)
+    #endif
+#endif
+
+
 class _CORBA_String_member {
 public:
   typedef char* ptr_t;
 
   inline _CORBA_String_member()
+#if HAS_CPP_CAST
+    : _ptr(const_cast<char*>(omni::empty_string)) {}
+#else
     : _ptr((char*) omni::empty_string) {}
+#endif
 
   inline _CORBA_String_member(const _CORBA_String_member& s) 
+#if HAS_CPP_CAST
+           : _ptr(const_cast<char*>(omni::empty_string)) {
+#else
            : _ptr((char*)omni::empty_string) {
+#endif
     if (s._ptr && s._ptr != omni::empty_string)
       _ptr = _CORBA_String_var::string_dup(s._ptr);
   }
@@ -319,7 +350,11 @@
       else
 	pd_data = 0;
     } else {
+#if HAS_CPP_CAST
+      pd_data = const_cast<char*>(s);
+#else
       pd_data = (char*)s;
+#endif
     }
     return *this;
   }
@@ -346,7 +381,11 @@
       else
 	pd_data = 0;
     } else
+#if HAS_CPP_CAST
+      pd_data = const_cast<char*>((const char*)s);
+#else
       pd_data = (char*)(const char*)s;
+#endif
     return *this;
   }
 
@@ -356,9 +395,17 @@
       if( (const char*)s && (const char*) s != omni::empty_string)
 	pd_data = _CORBA_String_var::string_dup((const char*)s);
       else
-	pd_data = (char*)(const char*)s;
+#if HAS_CPP_CAST
+      pd_data = const_cast<char*>((const char*)s);
+#else
+      pd_data = (char*)(const char*)s;
+#endif
     } else
+#if HAS_CPP_CAST
+      pd_data = const_cast<char*>((const char*)s);
+#else
       pd_data = (char*)(const char*)s;
+#endif
     return *this;
   }
 
@@ -559,7 +606,11 @@
 
     // If we've shrunk we need to clear the entries at the top.
     for( _CORBA_ULong i = len; i < pd_len; i++ ) 
+#if HAS_CPP_CAST
+      operator[](i) = const_cast<char*>(omni::empty_string);
+#else
       operator[](i) = (char*) omni::empty_string;
+#endif
 
     if (len) {
       // Allocate buffer on-demand. Either pd_data == 0 
@@ -587,7 +638,11 @@
     b[0] = (char*) ((omni::ptr_arith_t) 0x53515354U);
     b[1] = (char*) l;
     for (_CORBA_ULong index = 2; index < (nelems+2); index++)
+#if HAS_CPP_CAST
+      b[index] = const_cast<char*>(omni::empty_string);
+#else
       b[index] = (char*)omni::empty_string;
+#endif
     return b+2;
   }
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic