C++ Usage Issues - Problems, Solutions, and Suggestions

Robert S. Grimes rsg at alum.mit.edu
Thu Jun 21 16:11:24 UTC 2007


Joel Sherrill wrote:
>
> + Please send a patch for everything you changed.  I don't
> care about the .c->.cc changes but the ones that improve
> the correctness of the code are VERY important.
Here it is.  After you made the other changes (CONFIGURE_APPLICATION,
#include file extern "C", rtems/confdefs.h), all that needed to be fixed
is in test.c.  Of course, it only generates warnings for the C compiler,
but they are errors for the C++ compiler.

--- netdemo/test.c    1998-08-21 09:26:06.000000000 -0400
+++ netdemo-cc/test.cc    2007-06-21 11:51:44.937500000 -0400
@@ -34,11 +34,11 @@
 void showbroad(int s)
 {
     int opt;
-    int optlen = sizeof opt;
+    socklen_t optlen = (socklen_t)(sizeof opt);
 
     if (getsockopt (s, SOL_SOCKET, SO_BROADCAST, &opt, &optlen) < 0)
         printf ("getsockopt failed: %s\n", strerror (errno));
-    printf ("Opt:%d    Optlen:%d\n", opt, optlen);
+    printf ("Opt:%d    Optlen:%d\n", opt, (int)optlen);
 }
 
 static
@@ -201,7 +201,7 @@
 {
     int s, s1;
     struct sockaddr_in myAddr, farAddr;
-    int addrlen;
+    socklen_t addrlen;
     rtems_id tid;
     rtems_task_priority my_priority;
     rtems_status_code sc;
@@ -223,7 +223,7 @@
         rtems_panic ("Can't listen on socket: %s", strerror (errno));
     for (;;) {
         printf ("Accept.\n");
-        addrlen = sizeof farAddr;
+        addrlen = (socklen_t)(sizeof farAddr);
         s1 = accept (s, (struct sockaddr *)&farAddr, &addrlen);
         if (s1 < 0)
             rtems_panic ("Can't accept connection: %s", strerror (errno));





More information about the users mailing list