Re: Walker/mutator prototype.

Поиск
Список
Период
Сортировка
От Greg Stark
Тема Re: Walker/mutator prototype.
Дата
Msg-id 874qw4w07s.fsf@stark.dyndns.tv
обсуждение исходный текст
Ответ на Walker/mutator prototype.  (Kurt Roeckx <Q@ping.be>)
Ответы Re: Walker/mutator prototype.  (Kurt Roeckx <Q@ping.be>)
Список pgsql-hackers
Kurt Roeckx <Q@ping.be> writes:

> I'm trying to change all the walkers and mutators to have a more
> strict prototype.  I had to do this with lots of casts.
> 
> I don't really like the idea of having all those generic pointer
> types (Node * and void *), but currently see no better way to deal
> with it.

This code is incorrect. You have to declare the function prototype to match
the parameters that will actually be passed, not to match how they'll be used.

By casting the function pointers you're confusing the compiler into thinking
the variables are already the correct format and don't need to be cast.

The correct way to write this type of code is to prototype the functions with
void* or Node* or whatever variables will actually be passed, then immediately
assign the arguments to a local variable of the correct type.

Admittedly I doubt you'll actually run into any problems on any architecture
you're likely to see. But the behaviour is undefined in ANSI 89 C. 

As a side-point, personally I find the profusion of casts at every callpoint
to be far uglier, and also more error-prone than the single cast at the
beginning of each call-back.

-- 
greg



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Greg Stark
Дата:
Сообщение: Re: ORDER BY and DISTINCT ON
Следующее
От: Neil Conway
Дата:
Сообщение: Re: ORDER BY and DISTINCT ON