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


Groups > comp.lang.c > #65296

Re: declarator

From Tim Rentsch <txr@alumni.caltech.edu>
Newsgroups comp.lang.c
Subject Re: declarator
Date 2015-07-11 08:44 -0700
Organization A noiseless patient Spider
Message-ID <kfnegkey9zb.fsf@x-alumni2.alumni.caltech.edu> (permalink)
References (4 earlier) <mmsocv$eqk$1@dont-email.me> <lnk2um2bv7.fsf@kst-u.example.com> <mmstuk$ldj$1@dont-email.me> <t434pahgvcplooij8kdp6kfap4u52bb430@4ax.com> <lnfv592pbv.fsf@kst-u.example.com>

Show all headers | View raw


Keith Thompson <kst-u@mib.org> writes:

> Barry Schwarz <schwarzb@dqel.com> writes:
> [...]
>>> "Keith Thompson" <kst-u@mib.org> wrote in message 
>>> news:lnk2um2bv7.fsf@kst-u.example.com...
>>>> "Bill Cunningham" <nospam@nspam.invalid> writes:
>
> [...]
>
>>>>> p.c:  In function 'main':
>>>>> p.c:8:8: warning: assignment makes pointer from integer without a cast
>>>>> [enabled by default]
>>>>>      pf = print("hello there");
>>>>>         ^
>>>>> p.c:9:5: warning: return makes integer from pointer without a cast 
>>>>> [enabled
>>>>> by default]
>>>>>      return pf;
>>>>>      ^
>>>>>
>>>>> I did not use -Wall either.  as the compiler says "enabled by
>>>>> default.  It compiles and runs.
>>
>> It compiles with diagnostics which you have chosen to ignore
>> (something that should not be done unless you have a VERY THOROUGH
>> understanding of what the diagnostic means) and APPEARS to run.
>> Since you don't know what you want to do, you have no idea if the
>> code accomplished same.  Given that you ended up assigning an int 0
>> to a pointer (making the pointer a NULL pointer which does not
>> point anywhere), any subsequent attempt to use the pointer to
>> actually call a function would have failed.  Please tell us this
>> was not your goal.
>
> Storing a null pointer in pf is the most likely consequence of
> assigning the int value 0 to pf, but it's not the only possibility.
> There is no implicit conversion from int to a pointer type -- other
> than the special case of a *constant* expression with the value 0,
> which is a null pointer constant.  Even an explicit conversion (a
> cast) from an integer 0 to a pointer does not necessarily yield a
> null pointer though it commonly does.
>
> The assignment is a constraint violation.  A compiler can simply
> reject it.  If it chooses to accept it the behavior is undefined.

I feel obliged to point out that there are different opinions on
this question.  I acknowledge your interpretation that this case
is one of undefined behavior.  I believe it is also reasonable
to interpret that Standard as saying this case is a constraint
violation, but if an implementation chooses to accept it then
the behavior is defined (ie, by the semantics of how assignment
and conversion work).  I don't object to you voicing your
opinion, but to be fair I think it should be pointed out that
there are other views on how the Standard should be interpreted
in such cases.

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


Thread

declarator "Bill Cunningham" <nospam@nspam.invalid> - 2015-06-28 21:58 -0400
  declarator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-06-28 19:14 -0700
    Re: declarator "Bill Cunningham" <nospam@nspam.invalid> - 2015-06-28 22:36 -0400
      Re: declarator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-06-28 19:46 -0700
      Re: declarator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-06-29 11:22 +0100
        Re: declarator "Bill Cunningham" <nospam@nspam.invalid> - 2015-06-29 16:07 -0400
        Re: declarator "Bill Cunningham" <nospam@nspam.invalid> - 2015-06-29 16:09 -0400
  Re: declarator Barry Schwarz <schwarzb@dqel.com> - 2015-06-28 21:51 -0700
  Re: declarator Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-06-29 11:08 +0100
    Re: declarator "Bill Cunningham" <nospam@nspam.invalid> - 2015-06-29 16:18 -0400
      Re: declarator Barry Schwarz <schwarzb@dqel.com> - 2015-06-29 14:23 -0700
        Re: declarator "Bill Cunningham" <nospam@nspam.invalid> - 2015-06-29 18:39 -0400
        Re: declarator "Bill Cunningham" <nospam@nspam.invalid> - 2015-06-29 20:39 -0400
          Re: declarator Keith Thompson <kst-u@mib.org> - 2015-06-29 19:01 -0700
            Re: declarator "Bill Cunningham" <nospam@nspam.invalid> - 2015-06-29 22:13 -0400
              Re: declarator Barry Schwarz <schwarzb@dqel.com> - 2015-06-29 20:45 -0700
                Re: declarator Keith Thompson <kst-u@mib.org> - 2015-06-30 08:22 -0700
                Re: declarator Tim Rentsch <txr@alumni.caltech.edu> - 2015-07-11 08:44 -0700
                Re: declarator "Bill Cunningham" <nospam@nspam.invalid> - 2015-06-30 12:48 -0400
                Re: declarator Barry Schwarz <schwarzb@dqel.com> - 2015-06-30 15:32 -0700
                Re: declarator John Bode <jfbode1029@gmail.com> - 2015-07-01 13:50 -0700
                Re: declarator gazelle@shell.xmission.com (Kenny McCormack) - 2015-07-01 21:57 +0000
                Re: declarator "Rick C. Hodgin" <rick.c.hodgin@gmail.com> - 2015-07-01 15:05 -0700
                Re: declarator "Bill Cunningham" <nospam@nspam.invalid> - 2015-07-02 20:34 -0400
  Re: declarator Jens Stuckelberger <Jens_Stuckelberger@nowhere.net> - 2015-06-29 14:55 +0000

csiph-web