Question 2.18

This program works correctly, but it dumps core after it finishes. Why?

	struct list {
		char *item;
		struct list *next;
	}

	/* Here is the main program. */

	main(argc, argv)
	{ ... }


A missing semicolon causes main to be declared as returning a structure. (The connection is hard to see because of the intervening comment.) Since structure-valued functions are usually implemented by adding a hidden return pointer (see question 2.9), the generated code for main() tries to accept three arguments, although only two are passed (in this case, by the C start-up code). See also questions 10.9 and 16.4.

References: CT&P Sec. 2.3 pp. 21-2


Read sequentially: prev next up top


This page by Steve Summit // Copyright 1995 // mail feedback