Path: csiph.com!optima2.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!1.eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed.straub-nv.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: declarator Date: Tue, 30 Jun 2015 08:22:44 -0700 Organization: None to speak of Lines: 48 Message-ID: References: <87d20eesim.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="945944de09706c9b4e29b53c9d2efdc2"; logging-data="31948"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/fmCK/lMxrvt9nr09++vCN" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:rvtUouTUkW0VH+u0lZVpTsEJVBk= sha1:JUtfUf6D7nWXVVdQi4X5d9LbnvQ= Xref: csiph.com comp.lang.c:64549 Barry Schwarz writes: [...] >>"Keith Thompson" wrote in message >>news:lnk2um2bv7.fsf@kst-u.example.com... >>> "Bill Cunningham" 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. >>> gcc has an unfortunate habit of issuing non-fatal warnings for code that >>> is unambiguously incorrect. -- Keith Thompson (The_Other_Keith) kst-u@mib.org 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"