Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #71776

Re: Making sense of warning about "initialization makes pointer from integer without a cast"

From James Kuyper <jameskuyper@verizon.net>
Newsgroups comp.lang.c
Subject Re: Making sense of warning about "initialization makes pointer from integer without a cast"
Date 2015-10-03 23:16 -0400
Organization A noiseless patient Spider
Message-ID <muq5i6$env$1@dont-email.me> (permalink)
References <muq3ie$6bc$1@speranza.aioe.org>

Show all headers | View raw


On 10/03/2015 10:40 PM, Morten W. Petersen wrote:
> Hi there.
> 
> In my project Smash XML, I'm getting a warning of an incompatible
> pointer type (version getting the error is here):
> 
> https://github.com/morphex/smash_xml/tree/d381c7e596769dbcf6f2c0811f0f3cfd59bb8709
> 
> And the error is this:
> 
> $ make
> gcc -std=c90 -Wall -Wno-implicit-function-declaration decode_xml.c 
> tests.c -g -o decode_xml -I.
> tests.c: In function `main':
> tests.c:228:34: warning: initialization makes pointer from integer 
> without a cast
>       struct xml_element *result = parse_file(file);
> 
> The function definition parse_file says that it will return a pointer,
> it also does in the function.
> 
> What's wrong here?

It's not the function definition that matters. It's the declaration for
that function which is visible at this point in the code. A function
definition inherently contains a function declaration, but that
declaration is visible only it the same translation unit, and only in
the part after the function definition. If you want to call the function
from any other part of the program, you should provide a declaration for
that function which is in scope at the point where the function is
called. Show us that declaration, and we may be able to figure out what
went wrong with this program.

My guess is that you don't have such a declaration visible, which would
be a bad mistake on your part - but it's consistent with your confusion
about the proper role of header files.
If you have no declaration in scope, since you're using C90, an
declaration is implicitly created, which returns an 'int'. The error
message you get is due to the fact that there's no implicit conversion
from 'int' to 'struct xml_element*'.

Note: this is a mis-feature of C90, which is why it was corrected in
C99. In C99, the wording that required creation of the implicit
declaration was dropped - if you don't have an explicit function
declaration in scope, the identifier for the function doesn't have any
declared type associated with it, violating the constraint in 6.5.5.2p1.

If you insist on coding to an obsolete standard, you'll have to learn to
live with a version of the language that has a lot of known defects that
have since been fixed.
-- 
James Kuyper

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Making sense of warning about "initialization makes pointer from integer without a cast" "Morten W. Petersen" <morphex@gmail.com> - 2015-10-04 04:40 +0200
  Re: Making sense of warning about "initialization makes pointer from integer without a cast" "Morten W. Petersen" <morphex@gmail.com> - 2015-10-04 04:59 +0200
    Re: Making sense of warning about "initialization makes pointer from integer without a cast" James Kuyper <jameskuyper@verizon.net> - 2015-10-03 23:23 -0400
    Re: Making sense of warning about "initialization makes pointer from integer without a cast" Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-10-04 13:47 +0100
      Re: Making sense of warning about "initialization makes pointer from integer without a cast" Eric Sosman <esosman@comcast-dot-net.invalid> - 2015-10-04 09:40 -0400
        Re: Making sense of warning about "initialization makes pointer from integer without a cast" "Morten W. Petersen" <morphex@gmail.com> - 2015-10-05 00:33 +0200
          Re: Making sense of warning about "initialization makes pointer from integer without a cast" James Kuyper <jameskuyper@verizon.net> - 2015-10-04 19:07 -0400
  Re: Making sense of warning about "initialization makes pointer from integer without a cast" Melzzzzz <mel@zzzzz.com> - 2015-10-04 05:08 +0200
  Re: Making sense of warning about "initialization makes pointer from integer without a cast" James Kuyper <jameskuyper@verizon.net> - 2015-10-03 23:16 -0400
    Re: Making sense of warning about "initialization makes pointer from integer without a cast" "Morten W. Petersen" <morphex@gmail.com> - 2015-10-04 05:23 +0200
      Re: Making sense of warning about "initialization makes pointer from integer without a cast" James Kuyper <jameskuyper@verizon.net> - 2015-10-03 23:34 -0400
        Re: Making sense of warning about "initialization makes pointer from integer without a cast" "Morten W. Petersen" <morphex@gmail.com> - 2015-10-04 05:50 +0200
          Re: Making sense of warning about "initialization makes pointer from integer without a cast" James Kuyper <jameskuyper@verizon.net> - 2015-10-04 13:49 -0400
            Re: Making sense of warning about "initialization makes pointer from integer without a cast" Richard Heathfield <rjh@cpax.org.uk> - 2015-10-04 19:11 +0100
              Re: Making sense of warning about "initialization makes pointer from integer without a cast" James Kuyper <jameskuyper@verizon.net> - 2015-10-04 15:12 -0400
                Re: Making sense of warning about "initialization makes pointer from integer without a cast" Richard Heathfield <rjh@cpax.org.uk> - 2015-10-04 20:52 +0100
                Re: Making sense of warning about "initialization makes pointer from integer without a cast" supercat@casperkitty.com - 2015-10-04 13:18 -0700
            Re: Making sense of warning about "initialization makes pointer from integer without a cast" "Morten W. Petersen" <morphex@gmail.com> - 2015-10-05 00:26 +0200
              Re: Making sense of warning about "initialization makes pointer from integer without a cast" Keith Thompson <kst-u@mib.org> - 2015-10-04 18:09 -0700
                Re: Making sense of warning about "initialization makes pointer from integer without a cast" supercat@casperkitty.com - 2015-10-04 19:55 -0700
      Re: Making sense of warning about "initialization makes pointer from integer without a cast" Keith Thompson <kst-u@mib.org> - 2015-10-04 15:10 -0700
  Re: Making sense of warning about "initialization makes pointer from integer without a cast" Geoff <geoff@invalid.invalid> - 2015-10-03 22:04 -0700
    Re: Making sense of warning about "initialization makes pointer from integer without a cast" "Morten W. Petersen" <morphex@gmail.com> - 2015-10-04 07:07 +0200
      Re: Making sense of warning about "initialization makes pointer from integer without a cast" Geoff <geoff@invalid.invalid> - 2015-10-03 23:29 -0700
  Re: Making sense of warning about "initialization makes pointer from   integer without a cast" Ian Collins <ian-news@hotmail.com> - 2015-10-04 19:18 +1300
  Re: Making sense of warning about "initialization makes pointer from integer without a cast" Siri Cruz <chine.bleu@yahoo.com> - 2015-10-03 23:29 -0700

csiph-web