README.Portability take 1

Neil Booth NeilB@earthling.net
Thu Jul 13 15:57:00 GMT 2000


Does this now get the description under "signed" correct, in view of
Michael's mails?

Neil.

Index: README.Portability
===================================================================
RCS file: README.Portability
diff -N README.Portability
--- /dev/null	Tue May  5 13:32:27 1998
+++ README.Portability	Thu Jul 13 15:55:51 2000
@@ -0,0 +1,85 @@
+Copyright (C) 2000 Free Software Foundation, Inc.
+
+This file is intended to contain a few notes about writing C code
+within GCC so that it compiles without error on the full range of
+compilers GCC needs to be able to compile on.
+
+The problem is that many ISO-standard constructs are not accepted by
+either old or buggy compilers, and we keep getting bitten by them.
+This knowledge until know has just been in people's heads, I thought
+I'd make a record of it so it will be useful to all.  Please add any
+problems as you come across them.
+
+I'm going to start from a base of the ISO c89 standard, since that is
+probably what most people code to naturally.  Obviously using
+constructs introduced after that is not a good idea.
+
+Unary +
+-------
+
+K+R C compilers and preprocessors have no notion of unary '+'.  Thus
+the following code snippet contains 2 portability problems.
+
+int x = +2;  /* int x = 2;  */
+#if +1       /* #if 1  */
+#endif
+
+
+void *
+------
+
+K+R C compilers have no concept of pointer to void.  The macro PTR is
+defined for you to use instead.
+
+    free ((void *) h->value.expansion);
+
+should be written
+
+    free ((PTR) h->value.expansion);
+
+
+Empty macro arguments
+---------------------
+
+The compiler on the Next system (possibly an old GCC?) does not like
+empty macro arguments.  Thus
+
+#define foo(x, y) x y
+foo (bar, )
+
+needs to be coded in some other way.
+
+
+signed keyword
+--------------
+
+The signed keyword for use on anything other than "signed char" or
+signed bitfields is an ISO invention, and K+R compilers do not like
+it.
+
+  signed short paramc;
+
+should be written
+
+  short paramc;
+
+
+Calling functions through pointers to functions
+-----------------------------------------------
+
+K+R C compilers require brackets around the dereferenced pointer
+variable.  For example
+
+typedef void (* cl_directive_handler) PARAMS ((cpp_reader *, const char *));
+      *p->handler (pfile, p->arg);
+
+needs to become
+
+      (*p->handler) (pfile, p->arg);
+
+
+TODO
+----
+
+Something about function prototypes and PARAMS, and portable
+stringification and token pasting.


More information about the Gcc-patches mailing list