This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
README.Portability take 1
- To: gcc-patches at gcc dot gnu dot org
- Subject: README.Portability take 1
- From: Neil Booth <NeilB at earthling dot net>
- Date: Fri, 14 Jul 2000 07:38:48 +0900
- Cc: Zack Weinberg <zack at wolery dot cumb dot org>
Here is my first attempt to get the ball rolling, with just what I
could think of off the top of my head.
I've put some things in a TODO since I've not got time to complete
them just now.
OK to commit?
Neil.
* README.Portability: New file.
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:37:07 2000
@@ -0,0 +1,84 @@
+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 is an ANSI 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.