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


Groups > comp.lang.c > #71771 > unrolled thread

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

Started by"Morten W. Petersen" <morphex@gmail.com>
First post2015-10-04 04:40 +0200
Last post2015-10-03 23:29 -0700
Articles 6 on this page of 26 — 11 participants

Back to article view | Back to comp.lang.c


Contents

  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

Page 2 of 2 — ← Prev page 1 [2]


#71873

FromKeith Thompson <kst-u@mib.org>
Date2015-10-04 15:10 -0700
Message-ID<lna8ryxp1t.fsf@kst-u.example.com>
In reply to#71778
"Morten W. Petersen" <morphex@gmail.com> writes:
> On 04.10.2015 05:16, James Kuyper wrote:
[...]
>> 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.
>
> Wow, OK.  So I'll need to generate a header file with functions
> declarations automatically then.

You'll need to generate a header file with function declarations
(specifically prototypes).  (Strictly speaking you don't *have*
to have a header file, but there's no good reason not to.)

Whether you do it automatically is up to you.

(Personally I'd copy the .c file to the .h file, then manually
edit it by adding include guards and deleting the function bodies.
On the other hand, I'd be more likely to have the .h file without
the .c file in the first place than vice versa.)

-- 
Keith Thompson (The_Other_Keith) kst-u@mib.org  <http://www.ghoti.net/~kst>
Working, but not speaking, for JetHead Development, Inc.
"We must do something.  This is something.  Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"

[toc] | [prev] | [next] | [standalone]


#71782

FromGeoff <geoff@invalid.invalid>
Date2015-10-03 22:04 -0700
Message-ID<k7c11b18ltb9gmkcfpc9dmvhathqh1a8cj@4ax.com>
In reply to#71771
On Sun, 4 Oct 2015 04:40:38 +0200, "Morten W. Petersen"
<morphex@gmail.com> 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?
>

Lacking a proper function declaration, the compiler implicitly defined
one as int parse_file(FILE *file);

You also fail to check the return value from fopen. You should write
something like:

  if (test_parse_file) {
    printf("test_parse_file\n");
    FILE* file = fopen("test.xml", "rb+");
    if (!file)
    {
      printf("ERROR: XML file not opened\n");
      exit(1);
    }
    parse_file(file);
  }
  /* Various parsing tools */
//...

The time you have wasted in this group discussing the merits of
creating automatic function declaration could have been better spent
copy-pasting your function signatures into a decode_xml.h.

Here, I'll get you started:

------------------ decode_xml.h ------------------
#include "globals.h"

#ifndef DECODE_XML_H
#define DECODE_XML_H

struct xml_element* parse_file(FILE *file);

#endif /* DECODE_XML_H */
------------------ decode_xml.h ------------------

[toc] | [prev] | [next] | [standalone]


#71783

From"Morten W. Petersen" <morphex@gmail.com>
Date2015-10-04 07:07 +0200
Message-ID<muqc6l$jdf$1@speranza.aioe.org>
In reply to#71782
On 04.10.2015 07:04, Geoff wrote:
[...]
> Lacking a proper function declaration, the compiler implicitly defined
> one as int parse_file(FILE *file);
>
> You also fail to check the return value from fopen. You should write
> something like:
>
>    if (test_parse_file) {
>      printf("test_parse_file\n");
>      FILE* file = fopen("test.xml", "rb+");
>      if (!file)
>      {
>        printf("ERROR: XML file not opened\n");
>        exit(1);
>      }
>      parse_file(file);
>    }
>    /* Various parsing tools */
> //...

OK.

> The time you have wasted in this group discussing the merits of
> creating automatic function declaration could have been better spent
> copy-pasting your function signatures into a decode_xml.h.

Well I've added makeheaders.c to the project which generates
the prototypes now, so all is well.

Maybe you'll save yourself some typing as well, look here at
the Makefile and makeheaders.c:

https://github.com/morphex/smash_xml

-Morten

[toc] | [prev] | [next] | [standalone]


#71788

FromGeoff <geoff@invalid.invalid>
Date2015-10-03 23:29 -0700
Message-ID<jfh11bp04q3f4f41rcv66qp30pokb77e1s@4ax.com>
In reply to#71783
On Sun, 4 Oct 2015 07:07:58 +0200, "Morten W. Petersen"
<morphex@gmail.com> wrote:

>On 04.10.2015 07:04, Geoff wrote:
>[...]
>> Lacking a proper function declaration, the compiler implicitly defined
>> one as int parse_file(FILE *file);
>>
>> You also fail to check the return value from fopen. You should write
>> something like:
>>
>>    if (test_parse_file) {
>>      printf("test_parse_file\n");
>>      FILE* file = fopen("test.xml", "rb+");
>>      if (!file)
>>      {
>>        printf("ERROR: XML file not opened\n");
>>        exit(1);
>>      }
>>      parse_file(file);
>>    }
>>    /* Various parsing tools */
>> //...
>
>OK.
>
>> The time you have wasted in this group discussing the merits of
>> creating automatic function declaration could have been better spent
>> copy-pasting your function signatures into a decode_xml.h.
>
>Well I've added makeheaders.c to the project which generates
>the prototypes now, so all is well.
>
>Maybe you'll save yourself some typing as well, look here at
>the Makefile and makeheaders.c:
>
>https://github.com/morphex/smash_xml
>

I don't like the output but it will do in a pinch for getting a
collection such as yours a header file where it's completely missing.
The output is very ugly and lacks guards against multiple inclusions.

Now, resize your buffers to something reasonable and your segfaults
will go away:

#define READ_BYTES 4096*10

in HANDLE_ERROR macro:
char buffer[1024];

in FAIL macro:
char buffer_abc[1024]

[toc] | [prev] | [next] | [standalone]


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

FromIan Collins <ian-news@hotmail.com>
Date2015-10-04 19:18 +1300
SubjectRe: Making sense of warning about "initialization makes pointer from integer without a cast"
Message-ID<d7bumjF2qdvU5@mid.individual.net>
In reply to#71771
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?

Using old C...

-- 
Ian Collins

[toc] | [prev] | [next] | [standalone]


#71787

FromSiri Cruz <chine.bleu@yahoo.com>
Date2015-10-03 23:29 -0700
Message-ID<chine.bleu-1812FB.23291903102015@88-209-239-213.giganet.hu>
In reply to#71771
In article <muq3ie$6bc$1@speranza.aioe.org>,
 "Morten W. Petersen" <morphex@gmail.com> 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/d381c7e596769dbcf6f2c0811f0f3cfd59bb
> 8709
> 
> 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.

Is the function declaration visible where you make the call?

-- 
:-<> Siri Seal of Disavowal #000-001. Disavowed. Denied. Deleted.
'I desire mercy, not sacrifice.'
When is a Kenyan not a Kenyan? When he's a Canadian.
That's People's Commissioner Siri Cruz now. Punch!

[toc] | [prev] | [standalone]


Page 2 of 2 — ← Prev page 1 [2]

Back to top | Article view | comp.lang.c


csiph-web