Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 26 Jan 1998 18:51:10 +1030
From:      Greg Lehey <grog@lemis.com>
To:        Brian Reichert <reichert@numachi.com>
Cc:        freebsd-questions@FreeBSD.ORG
Subject:   Re: gcc -Wall wierdness?
Message-ID:  <19980126185110.07585@lemis.com>
In-Reply-To: <19980126023315.47723@numachi.com>; from Brian Reichert on Mon, Jan 26, 1998 at 02:33:15AM -0500
References:  <19980126023315.47723@numachi.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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 <stdio.h>
> #include <string.h>
>
> 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 <string.h>, 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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19980126185110.07585>