Date: Mon, 25 Oct 2004 11:41:54 -0400 From: Charles Swiger <cswiger@mac.com> To: Richard Williamson <richard.williamson@u4eatech.com> Cc: freebsd-questions@freebsd.org Subject: Re: odd warning message from gcc under FreeBSD 4.10 Message-ID: <65CE1486-269C-11D9-9067-003065ABFD92@mac.com> In-Reply-To: <417D18DF.1040607@u4eatech.com> References: <417D18DF.1040607@u4eatech.com>
next in thread | previous in thread | raw e-mail | index | archive | help
On Oct 25, 2004, at 11:16 AM, Richard Williamson wrote: > Is this something known about, or: What am I missing? > > TIA, > rip > > PROBLEM: > > man strstr says: returns char * > test code throws warning on line 7: > test.c:7: warning: assignment makes pointer from integer \ > without a cast [ ...see previous message in thread for example C program... ] Using -Wall will help clarify the situation for you: 6-ns1% cc -Wall -o red red.c red.c:2: warning: second argument of `main' should be `char **' red.c: In function `main': red.c:7: warning: implicit declaration of function `strstr' red.c:7: warning: assignment makes pointer from integer without a cast red.c:9: warning: implicit declaration of function `printf' red.c:12: warning: control reaches end of non-void function In other words, you ought to add: #include <stdio.h> #include <string.h> ...to the top of your sample program so that the prototypes for strstr() and printf() are known. Otherwise, the compiler guesses that the return value for an unknown function is an int, or will fit into one. On platforms where sizeof(int) == sizeof(void *), your code will work fine. On platforms where that is not the case-- such as the so-called "LP64" architectures-- such code will break. -- -Chuck
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?65CE1486-269C-11D9-9067-003065ABFD92>