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


Groups > comp.lang.c > #71891

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-04 19:07 -0400
Organization Self
Message-ID <5611B130.5020205@verizon.net> (permalink)
References (1 earlier) <definition-20151004035415@ram.dialup.fu-berlin.de> <muq4lq$7eo$1@speranza.aioe.org> <87r3lan6lv.fsf@bsb.me.uk> <mura4l$50b$1@dont-email.me> <mus9ee$t2j$1@speranza.aioe.org>

Show all headers | View raw


On 10/04/2015 06:33 PM, Morten W. Petersen wrote:
> On 04.10.2015 15:40, Eric Sosman wrote:
> [...]
>>      Seconded -- thirded, and N'thed.
>>
>>      In another thread, Morten W. Peterson refers to "when prototypes
>> are added," as a sort of late-stage cross-the-eyes-and-dot-the-tees
>> final cleanup.  One lesson to be learned from the experience recounted
>> in this thread is that prototypes are of greatest value *during* the
>> development phase.  They are not the fancy ribbons that are the last
>> bits you add to a gift box, but tools to help make the gift itself.
>>
>>      Write prototypes first, not finally.
> 
> I think that's a matter of programming style.  I'm used to writing in
> Python, so just dishing out a function is natural to me.

By delaying the creation of function prototypes, you're depriving
yourself of valuable bug-detection capabilities that have their greatest
value during the early stages of development. It's a foolish kind of
laziness that delays creation of the prototype until after it has become
less useful. Also, a declaration (not necessarily a prototype) is needed
in scope whenever you call a function whose return value is anything
other than 'int' - which is precisely the problem that this thread is about.

If a function is declared with a prototype that's in scope at the point
of a function call, arguments that can be implicitly converted to the
type of the corresponding parameter, are so converted; without a
prototype, the default argument promotions occur.  If you ever write a
function prototype which declares a parameter type that is incompatible
with the promoted type of the corresponding argument, then the type of
the value passed to the function will change when the prototype is
introduced. If such code had defined behavior before the prototype was
introduced, then the prototype doesn't correctly match the function
definition, so introducing the function prototype will cause the
behavior to become undefined.

Therefore, it's a good idea to introduce the prototype at the same time
as the function definition, or even before then, so you can start
debugging any such mismatches as soon as possible.

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