From owner-freebsd-questions Mon Jan 26 00:21:25 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id AAA24349 for questions-outgoing; Mon, 26 Jan 1998 00:21:25 -0800 (PST) (envelope-from owner-freebsd-questions@FreeBSD.ORG) Received: from allegro.lemis.com (allegro.lemis.com [192.109.197.134]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id AAA24335 for ; Mon, 26 Jan 1998 00:21:20 -0800 (PST) (envelope-from grog@lemis.com) Received: from freebie.lemis.com (freebie.lemis.com [192.109.197.137]) by allegro.lemis.com (8.8.7/8.8.5) with ESMTP id SAA19075; Mon, 26 Jan 1998 18:51:11 +1030 (CST) Received: (from grog@localhost) by freebie.lemis.com (8.8.8/8.8.7) id SAA05235; Mon, 26 Jan 1998 18:51:10 +1030 (CST) (envelope-from grog) Message-ID: <19980126185110.07585@lemis.com> Date: Mon, 26 Jan 1998 18:51:10 +1030 From: Greg Lehey To: Brian Reichert Cc: freebsd-questions@FreeBSD.ORG Subject: Re: gcc -Wall wierdness? References: <19980126023315.47723@numachi.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.84e In-Reply-To: <19980126023315.47723@numachi.com>; from Brian Reichert on Mon, Jan 26, 1998 at 02:33:15AM -0500 Organization: LEMIS, PO Box 460, Echunga SA 5153, Australia Phone: +61-8-8388-8286 Fax: +61-8-8388-8725 Mobile: +61-41-739-7062 WWW-Home-Page: http://www.lemis.com/~grog Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk On Mon, Jan 26, 1998 at 02:33:15AM -0500, Brian Reichert wrote: > Howdy- > > I'm running 2.2.2-R, with gcc 2.7.2.1, and am getting a weird symptom: > > With this simple program: > > --------------------------------- > #include > #include > > void main () > { > printf("read failed: %s\n", strerror[0]); >> > --------------------------------- > > gcc -Wall yields, upon compiling: > > foo.c: In function `main': > foo.c:6: warning: char format, different type arg (arg 2) > > So, what gives? strerror(3) says to pull in , which > seems to prototype it as char *. Is this a GNU bad, or has FreeBSD > done something clever, or (horrors) am I missing the point entirely? Assuming that's really the program, you're missing the point. You're using the function as an array (strerror [0] instead of strerror (0)). I don't know why gcc didn't complain about that, but maybe it's legal (strerror [0] = *sterror). What I don't understand is how you can subscript a scalar function. The assembler output indicates that it's just using the address of the function: LC0: .ascii "read failed: %s\12\0" .align 2 .globl _main .type _main,@function _main: pushl %ebp movl %esp,%ebp call ___main pushl $_strerror ; 2nd parm: address of strerror pushl $LC0 ; 1st parm: format string call _printf Certainly if you change this to: printf ("read failed: %s\n", strerror (0)); things look a whole lot better. Alternatively, you could write printf ("read failed: %s\n", sys_errlist [0]); which is probably what was confusing you. Greg