[net.lang.c] Escaped from the Language Lab

dick@tjalk.UUCP (Dick Grune) (03/21/84)

Now that I'm posting to the net anyway, I might just as well unleash
to the world the following C program that I have kept carefully caged
in a highly protected directory until now.

It is totally amoral and only serves for your education, edification,
enjoyment and/or annoyment. (It compiles and runs on our VAX 4.1 BSD)

					Dick Grune
					Vrije Universiteit
					Amsterdam
And my name isn't Richard!

/* Escaped from the Language Lab */

#define	STDIO_H	<stdio.h>
#include	STDIO_H		/* logical, but ... */

/* some weird (external) declarations */
;
var;
int;

/* weird order */
char static cc;

/* reserved word entry */
int entry;
int entry;			/* may be declared twice */

int ii[][/* 15, */ 2] =	/* comma in index not allowed, however see below */
/* commas in initializer_lists at all levels */
	{	{041, 042, },
		{043, 044, },
	};

/* extern function_body */
extern int
main(u, v) /* some crazy decls */ char *v[100]; int;	{
	/* funny order */
	char register qq;

	/* weird initializer */
	int a, b = a = 3, d = 5;   /* are declarations done left-to-right ? */

	/* sum of string and int */
	char *p = "abcde" + 2;

	printf("a = %d (3), b = %d (3)\n", a, b);
	printf("*p = %c (c)\n", *p);

	/* assignments inside conditional expression */
	printf("cond = %d (4)\n", a > 1 ? b = 4 : (d = 2));
						/* just d = 2 is wrong */
	printf("b = %d (4), d = %d (5)\n", b, d);

	/* strange parsing */
	qq = b---a;	/* b-- - a */
	printf("qq = %d (1), a = %d (3), b = %d (3)\n", qq, a, b);

	/* comma in index */
	qq = ii[5, 1][7, 0];		/* just an expression, RM 7.15 */
	printf("qq = %o (43)\n", qq);

	/* space in assignment operator */
	d + /* space */ = 3;
	printf("d = %d (8)\n", d);

	/* sizeof sizeof */
	printf("sizeof sizeof d = %d (%d)\n", sizeof sizeof d, sizeof (int));

	/* non-obvious cast */
	{	typedef	int c;
		printf("(c) - (a+b) = %d (-6)\n", (c) - (a+b));
	}

	/* legal (?) multiple declaration */
	{	int j = a + 3;			/* the `a' from `main' */
		char a = 22;			/* a new `a' */

		printf("j = %d (6), a = %d (22)\n", j, a);
	}
	return 0;
}