Wy compiler is rejecting the simplest possible test programs ...

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;
}

✍: Guest

A

Perhaps it is a pre-ANSI compiler, unable to accept function prototypes and the like.
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() { ... }

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;
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
6. Remove const and volatile qualifiers.
7. Modify any initialized automatic aggregates
8. Use older library functions
9. Re-work any preprocessor macros involving # or ##
10. Rework conditional compilation involving #elif.
11. Convert from the facilities of <stdarg.h> to <varargs.h>
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.

2015-12-02, 1193👍, 0💬