Re: Walker/mutator prototype. - Mailing list pgsql-hackers

From Greg Stark
Subject Re: Walker/mutator prototype.
Date
Msg-id 87n09vuyt7.fsf@stark.dyndns.tv
Whole thread Raw
In response to Re: Walker/mutator prototype.  (Kurt Roeckx <Q@ping.be>)
Responses Re: Walker/mutator prototype.  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Kurt Roeckx <Q@ping.be> writes:

> I did start by changing all the context's to void *, but you'll
> loose the real type that it gets called with, so the other calls
> will not generate warnings anymore because of wrong type.  

But at least you'll get a warning if someone passes a non-pointer or an
incorrect number of arguments altogether.

> So I just casted the function pointers to the right type.

But that means you'll *never* get a warning. Even if someone passes a function
that's completely inappropriate. That seems worse than the disease. 

Plus it's simply wrong since the compiler might actually invoke the function
incorrectly. When you call the function you have to call it through a function
pointer with the same type as the prototype the function was defined with to
guarantee all the casts are performed and the proper calling convention is
followed.

-- 
greg



pgsql-hackers by date:

Previous
From: Bruno Wolff III
Date:
Subject: Re: ORDER BY and DISTINCT ON
Next
From: Bruce Momjian
Date:
Subject: Re: [PATCHES] fork/exec patch