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


Groups > comp.lang.c > #136752

Re: Unwanted, implicit type conversion to a pointer when a value is zero?

From Keith Thompson <kst-u@mib.org>
Newsgroups comp.lang.c
Subject Re: Unwanted, implicit type conversion to a pointer when a value is zero?
Date 2018-10-13 11:37 -0700
Organization None to speak of
Message-ID <lny3b1vgjz.fsf@kst-u.example.com> (permalink)
References <eaf12c90-58a9-4a8f-b12f-4c0f79a50c59@googlegroups.com> <G9nwD.18529$I34.17228@fx43.am4>

Show all headers | View raw


Bart <bc@freeuk.com> writes:
> On 13/10/2018 01:12, jladasky@itu.edu wrote:
>> Now, I know that I've made an error in each case, I need to supply a
>> pointer to a data buffer for that third argument rather than (in my
>> cases a single byte of) the data that I want to send.  However, I am
>> surprised that the first function call does not generate an error if
>> that is true.  GCC was happy to cast 0x00 to a pointer (probably to
>> NULL?).  It only complained when I tried to cast 0x01 to a pointer.
>> Is this expected?  Desirable?
>
>
> The value of 0 is very commonly used to indicate a pointer that doesn't 
> point to anything (or, for example, that this particular call is not 
> supplying that argument so it should not be used).
>
> But what would a value of 1 mean in your program?
>
> It is most likely an error. That's why you need to explicitly cast a 
> constant integer to a pointer, it is not zero (and all variable 
> integers). To show here that passing 1 for a pointer is intentional.

The OP already said that he knows it's an error.  He's asking why the
error was diagnosed for 0x01 but not for 0x00 (and that's been
answered).

-- 
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"

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


Thread

Unwanted, implicit type conversion to a pointer when a value is zero? jladasky@itu.edu - 2018-10-12 17:12 -0700
  Re: Unwanted, implicit type conversion to a pointer when a value is zero? David Brown <david.brown@hesbynett.no> - 2018-10-13 12:54 +0200
    Re: Unwanted, implicit type conversion to a pointer when a value is zero? Keith Thompson <kst-u@mib.org> - 2018-10-13 11:36 -0700
  Re: Unwanted, implicit type conversion to a pointer when a value is zero? Bart <bc@freeuk.com> - 2018-10-13 15:19 +0100
    Re: Unwanted, implicit type conversion to a pointer when a value is zero? Keith Thompson <kst-u@mib.org> - 2018-10-13 11:37 -0700
      Re: Unwanted, implicit type conversion to a pointer when a value is zero? Bart <bc@freeuk.com> - 2018-10-13 20:21 +0100
        Re: Unwanted, implicit type conversion to a pointer when a value is zero? Keith Thompson <kst-u@mib.org> - 2018-10-13 12:57 -0700

csiph-web