[comp.lang.c] Summary of deANSIfiers.

flee@shire.cs.psu.edu (Felix Lee) (03/23/89)

I received several answers to my request for a program to undo ANSI
function prototypes.

The winner is "cfront", AT&T's C++ compiler, which generates pre-ANSI
C code.  This is a bit heavy if all you want is a deprototyper.  If
you're not going to be using C++'s features, you might as well get a
native ANSI C compiler.  "cfront" may be easier to port though.

Honorable mention goes to AGCPP, by Alistair G. Crooks <uunet!linus!
nixbur!nixpbe!nixbln!agc>, posted to comp.os.minix 20 Feb 89.  This
tries to be an ANSI-conforming C preprocessor that also deANSIfies
your program for your non-ANSI compiler.  Pathological prototypes
confuse it though.

Smaller and simpler, Robert Lupton <lupton@uhccux.uhcc.hawaii.edu>
sent me a short lex program that he will post to comp.sources.misc.
Lawrence C. Foard <lfoard@wpi.wpi.edu> sent me a similar program
written in C.

Here is my pathological test file:

------------Start of pathological.c
int getchar(void);						/* 1a */
int printf(const char *, ...);					/* 1b */
long atol(char *), strtol(char *, char **, int);		/* 1c */

void (*signal(int, void (*)(int)))(int);			/* 2a */
void (*signal(int sig, void (*f)(int)))(int) { }		/* 2b */

double a (double b /* comment */, double o) {			/* 3a */
	extern char * iot(const char *);			/* 3b */
	{ extern char * ity(int, int); }			/* 3c */
}

void var(const char * fmt, ...) { }				/* 4 */

char *(d1), (*(d2))[], *((d3)[]);				/* 5 */

struct t { int (*x)(y); };					/* 6 */

struct { int x, y; } xyz(struct { int x, y; } a) { }		/* 7 */

int add(a, b) int a; int b; { }					/* 8 */

------------End of pathological.c

GNU cc (1.34) digests the whole file happily.

"cfront" (1.20) passes everything but:
2b. it misplaces the outer set of parentheses;
5. it claims a syntax error;
6. it claims a syntax error (replacing "y" with "int y" fixes this);
7. it doesn't support "struct {} xyz ()" (yet).

The other deANSIfiers get less than half of the tests correct.

None of the deANSIfiers will give you any warning that it has
produced mangled output.
--
Felix Lee	flee@shire.cs.psu.edu	*!psuvax1!shire!flee

djones@megatest.UUCP (Dave Jones) (03/24/89)

From article <4399@psuvax1.cs.psu.edu), by flee@shire.cs.psu.edu (Felix Lee):
) I received several answers to my request for a program to undo ANSI
) function prototypes.
) 
) The winner is "cfront", AT&T's C++ compiler, which generates pre-ANSI
) C code.  This is a bit heavy if all you want is a deprototyper.  If
) you're not going to be using C++'s features, you might as well get a
) native ANSI C compiler.  "cfront" may be easier to port though.
) 

Will it not fail on foo(void), or the very popular foo()?

That's a biggy.  I know because I had to translate a jillion .h
files when I installed C++ here.  My initial rapture with C++ turned
into muttering, "Why-oh-why didn't they make it a superset? They
said they did, darn it. Grumble, mumble."

I seem to recall that there were other ways in which C++ is not
a superset of either C or ANSII-C, but I can't remember just how.
Maybe it is just my imagination.

In any case, I don't think cfront by itself will always the job
of deANSIIfying.