Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 25 Oct 2004 20:15:28 +0200
From:      Erik Trulsson <ertr1013@student.uu.se>
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:  <20041025181528.GA15867@falcon.midgard.homeip.net>
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 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 <string.h>' (as well as an 
'#include <stdio.h>')
Since <string.h> 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>

-- 
<Insert your favourite quote here.>
Erik Trulsson
ertr1013@student.uu.se



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