Hi all,

I was thinking about asking the community its stance on C99, and this
seems like a good point to do so.  The tree appears to be ISO C99
compliant, with the exception of a few GNU C library extensions.
I was just able to compile r1516 using both -std=gnu99 and -std=c99,
though the later requires including couple of additional header files.  

The attached openocd-add-missing-headers.patch adds the potentially
required includes; I referenced my installed man pages for FD_SET and
strcasecmp for fixes.  This patch may not be portable to all supported
platforms, but I believe it should be.  This patch may turn out to be a
moot point, but it seems more technically correct in its adherence to
the documentation that I have here.  Others may confirm or deny this.

The other patches give three different options for making gcc fully
enable its C99 mode.  The first simply adds -std=gnu99; for some reason,
it does not require the missing headers patch.  The other patches use
-std=c99 and either "-D_BSD_SOURCE -D_POSIX_SOURCE" or
"-D_XOPEN_SOURCE=500", either of which requires the headers patch.  
For some reason, neither of those seem quite "right", but neither does
-std=gnu99 for that matter.  I am not an expert in this particular area,
but my gut tells me there may be a reason not to add either of these.

I am curious what effects this has for other platforms.  Could folks
please report on CygWin, MinWG32, MacOS, Debian/Ubuntu, and any others
before we see any of these committed?  Of course, that assumes y'all
have any interest in these in the first place....

Cheers,

Zach

Index: src/helper/replacements.h
===================================================================
--- src/helper/replacements.h	(revision 1520)
+++ src/helper/replacements.h	(working copy)
@@ -43,6 +43,8 @@
 #include <winsock2.h>
 #include <ws2tcpip.h>
 #else
+#include <sys/time.h>
+#include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/poll.h>
 #include <netinet/in.h>
Index: src/jtag/jtag.c
===================================================================
--- src/jtag/jtag.c	(revision 1520)
+++ src/jtag/jtag.c	(working copy)
@@ -35,9 +35,10 @@
 #include "command.h"
 #include "log.h"
 
-#include "stdlib.h"
-#include "string.h"
+#include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
+#include <strings.h>
 
 /* note that this is not marked as static as it must be available from outside jtag.c for those
    that implement the jtag_xxx() minidriver layer
Index: configure.in
===================================================================
--- configure.in	(revision 1520)
+++ configure.in	(working copy)
@@ -795,6 +795,7 @@
 	CC_FOR_BUILD=$CC
 	CFLAGS_FOR_BUILD=$CFLAGS
 fi
+CFLAGS="$CFLAGS -std=c99 -D_POSIX_SOURCE -D_BSD_SOURCE"
 
 AC_MSG_RESULT([$CC_FOR_BUILD])
 AC_SUBST(CC_FOR_BUILD)
Index: configure.in
===================================================================
--- configure.in	(revision 1520)
+++ configure.in	(working copy)
@@ -795,6 +795,7 @@
 	CC_FOR_BUILD=$CC
 	CFLAGS_FOR_BUILD=$CFLAGS
 fi
+CFLAGS="$CFLAGS -std=c99 -D_XOPEN_SOURCE=500"
 
 AC_MSG_RESULT([$CC_FOR_BUILD])
 AC_SUBST(CC_FOR_BUILD)
Index: configure.in
===================================================================
--- configure.in	(revision 1520)
+++ configure.in	(working copy)
@@ -795,6 +795,7 @@
 	CC_FOR_BUILD=$CC
 	CFLAGS_FOR_BUILD=$CFLAGS
 fi
+CFLAGS="$CFLAGS -std=gnu99"
 
 AC_MSG_RESULT([$CC_FOR_BUILD])
 AC_SUBST(CC_FOR_BUILD)
_______________________________________________
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development

Reply via email to