prev up next   top/contents search

comp.lang.c FAQ list · Question 11.29a

Q: My compiler is rejecting the simplest possible test programs, with all kinds of syntax errors. It's complaining about the first line of

	main(int argc, char **argv)
	{
		return 0;
	}


A: Perhaps it is a pre-ANSI compiler, unable to accept function prototypes and the like.

See also questions 1.31, 10.9, 11.30, and 16.1b.

If you don't have access to an ANSI compiler, and you need to convert some newer code (such as that in this list) so that you can compile it, perform these steps:

  1. Remove the argument type information from function prototype declarations, and convert prototype-style function definitions to old style. The new-style declarations
    	extern int f1(void);
    	extern int f2(int);
    	int main(int argc, char **argv) { ... }
    	int f3(void) { ... }
    
    would be rewritten as
    	extern int f1();
    	extern int f2();
    	int main(argc, argv) int argc; char **argv; { ... }
    	int f3() { ... }
    
    (Beware of parameters with ``narrow'' types; see question 11.3.)
  2. Replace void * with char * .
  3. Perhaps insert explicit casts where converting between ``generic'' pointers (void *, which you've just replaced with char *) and other pointer types (for instance in calls to malloc and free, and in qsort comparison functions; see questions 7.7 and 13.9).
  4. Insert casts when passing the ``wrong'' numeric types as function arguments, e.g. sqrt((double)i);.
  5. Rework calls to realloc that use NULL or 0 as first or second arguments (see question 7.30).
  6. Remove const and volatile qualifiers.
  7. Modify any initialized automatic aggregates (see question 1.31).
  8. Use older library functions (see question 13.24).
  9. Re-work any preprocessor macros involving # or ## (see questions 10.20, 10.21, and 11.18).
  10. Rework conditional compilation involving #elif.
  11. Convert from the facilities of <stdarg.h> to <varargs.h> (see question 15.7).
  12. Cross your fingers. (In other words, the steps listed here are not always sufficient; more complicated changes may be required which aren't covered by any cookbook conversions.)

It is possible to make many of these changes with the preprocessor rather than by editing source code.

See also the Rationale's list of ``quiet changes'' (see question 11.2).

See also question 11.31.


prev up next   contents search
about this FAQ list   about eskimo   search   feedback   copyright

Hosted by Eskimo North