Question 11.16

Is exit(status) truly equivalent to returning the same status from main?


Yes and no. The Standard says that they are equivalent. However, a few older, nonconforming systems may have problems with one or the other form. Also, a return from main cannot be expected to work if data local to main might be needed during cleanup; see also question 16.4. (Finally, the two forms are obviously not equivalent in a recursive call to main.)

References: K&R2 Sec. 7.6 pp. 163-4
ANSI Sec. 2.1.2.2.3
ISO Sec. 5.1.2.2.3


Read sequentially: prev next up top


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