From owner-freebsd-questions@FreeBSD.ORG Mon Oct 25 18:15:33 2004 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id B937116A4D5 for ; Mon, 25 Oct 2004 18:15:33 +0000 (GMT) Received: from av11-2-sn4.m-sp.skanova.net (av11-2-sn4.m-sp.skanova.net [81.228.10.105]) by mx1.FreeBSD.org (Postfix) with ESMTP id 8B8C343D4C for ; Mon, 25 Oct 2004 18:15:32 +0000 (GMT) (envelope-from ertr1013@student.uu.se) Received: by av11-2-sn4.m-sp.skanova.net (Postfix, from userid 502) id 6A17137E4B; Mon, 25 Oct 2004 20:15:31 +0200 (CEST) Received: from smtp4-1-sn4.m-sp.skanova.net (smtp4-1-sn4.m-sp.skanova.net [81.228.10.181]) by av11-2-sn4.m-sp.skanova.net (Postfix) with ESMTP id 59E9837E46 for ; Mon, 25 Oct 2004 20:15:31 +0200 (CEST) Received: from falcon.midgard.homeip.net (h201n1fls24o1048.bredband.comhem.se [212.181.162.201]) by smtp4-1-sn4.m-sp.skanova.net (Postfix) with SMTP id 8A5DF37E47 for ; Mon, 25 Oct 2004 20:15:30 +0200 (CEST) Received: (qmail 15940 invoked by uid 1001); 25 Oct 2004 18:15:28 -0000 Date: Mon, 25 Oct 2004 20:15:28 +0200 From: Erik Trulsson To: Richard Williamson Message-ID: <20041025181528.GA15867@falcon.midgard.homeip.net> Mail-Followup-To: Richard Williamson , freebsd-questions@freebsd.org References: <417D18DF.1040607@u4eatech.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <417D18DF.1040607@u4eatech.com> User-Agent: Mutt/1.5.6i cc: freebsd-questions@freebsd.org Subject: Re: odd warning message from gcc under FreeBSD 4.10 X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Oct 2004 18:15:33 -0000 On Mon, Oct 25, 2004 at 04:16:47PM +0100, Richard Williamson wrote: > Hello, > > Is this something known about, or: What am I missing? You are missing an '#include ' (as well as an '#include ') Since isn't included the compiler does not know what the return type of strstr() is, and therefore assumes the return-type to be 'int' by default. If you add a '-Wall' when you invoke the compiler on the code below you will get the following warnings (all of which are valid and point out problems with your code): test.c:3: warning: second argument of `main' should be `char **' test.c: In function `main': test.c:7: warning: implicit declaration of function `strstr' test.c:7: warning: assignment makes pointer from integer without a cast test.c:8: warning: implicit declaration of function `printf' test.c:11: warning: control reaches end of non-void function > > 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 > > > TEST CODE > int main (int argc, void ** argv) > { > char *pBlah = 0x0; > char rudolph[64] = "Rudolph the Red Nosed Reindeer"; > char red[4] = "Red"; > > pBlah = strstr(rudolph, red); > > printf("1: %s\n", rudolph); > printf("2: %s\n", red); > printf("3: %s\n", pBlah); > } > > TEST COMPILE (linux) > bash-2.05b# gcc -o test test.c > bash-2.05b# uname -a > Linux mir 2.6.8-gentoo-r7 #1 Mon Oct 11 14:18:22 BST 2004 \ > i686 Intel(R) Pentium(R) 4 CPU 2.80GHz GenuineIntel GNU/Linux > bash-2.05b# ./test > 1: Rudolph the Red Nosed Reindeer > 2: Red > 3: Red Nosed Reindeer > bash-2.05b# > > TEST COMPILE (FreeBSD) > venus 17:11 [~/cassess2] rip>gcc -o test test.c > test.c: In function `main': > test.c:7: warning: assignment makes pointer from integer \ > without a cast > venus 17:11 [~/cassess2] rip>uname -a > FreeBSD venus.degree2.com 4.10-RELEASE FreeBSD 4.10-RELEASE #0: \ > Tue May 25 22:47:12 GMT 2004 > root@perseus.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC i386 > venus 17:12 [~/cassess2] rip>./test > 1: Rudolph the Red Nosed Reindeer > 2: Red > 3: Red Nosed Reindeer > venus 17:12 [~/cassess2] rip> -- Erik Trulsson ertr1013@student.uu.se