"Strong typing vs. strong testing"

Seebs usenet-nospam at seebs.net
Thu Sep 30 15:21:58 EDT 2010


On 2010-09-30, Keith Thompson <kst-u at mib.org> wrote:
> Seebs <usenet-nospam at seebs.net> writes:
>> On 2010-09-30, Paul Rubin <no.email at nospam.invalid> wrote:
>>>     int maximum(int a, int b);

>>>     int foo() {
>>>       int (*barf)() = maximum;
>>>       return barf(3);
>>>     }

> That first line declare barf as an object of type "pointer to
> function returning int", or more precisely, "pointer to function with
> an unspecified but fixed number and type of parameters returning int"
> (i.e., an old-style non-prototype declaration, still legal but
> deprecated in both C90 and C99).  It then initializes it to point
> to the "maximum" function.  I *think* the types are sufficiently
> "compatible" (not necessarily using that word the same way the
> standard does) for the initialization to be valid and well defined.
> I might check the standard later.

Hmm.  You have a point.  It's clearly a conversion from one type
to another.

> IMHO it's better to use prototypes consistently than to figure out the
> rules for interactions between prototyped vs. non-prototyped function
> declarations.

Yes.  It's clearly undefined behavior to call a function through a
pointer to a different type, or to call a function with the wrong number
of arguments.  I am pretty sure at least one compiler catches this.

-s
-- 
Copyright 2010, all wrongs reversed.  Peter Seebach / usenet-nospam at seebs.net
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.



More information about the Python-list mailing list