Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site eagle.UUCP Path: utzoo!watmath!clyde!burl!ulysses!eagle!mjs From: mjs@eagle.UUCP (M.J.Shannon) Newsgroups: net.lang.c Subject: Re: casts to (void) Message-ID: <1288@eagle.UUCP> Date: Fri, 19-Jul-85 23:45:38 EDT Article-I.D.: eagle.1288 Posted: Fri Jul 19 23:45:38 1985 Date-Received: Sat, 20-Jul-85 12:19:59 EDT References: <11@brl-tgr.ARPA> Organization: AT&T Bell Laboratories, Summit, NJ Lines: 27 > > Why should a cast to (void) be necessary in a statement like > > (void) printf("foo\n"); > > ? Why not say that the expression in the definition > = ";" is automatically cast to type void? > > Gary Ansok The cast is necessary because printf() returns a value. Lint (very properly) warns that the value is unused without the cast. Would you prefer that lint say nothing if you had a code fragment something like: ... log(d); ... Insofar as the language is concerned, failing to do *something* with a returned value is at least suspect. Casting the value to void *does* use the value, but should generate no extra code; in some implementations, it could allow better code generation because the compiler is told explicitly to ignore the value, perhaps leaving more (or different) registers available for subsequent code. -- Marty Shannon UUCP: ihnp4!eagle!mjs Phone: +1 201 522 6063