On Wed, 01 Jun 2011 18:54:38 +0200
Pierre <p.vit...@laposte.net> wrote:

> This patch is about the pragmas.
> 
> In c-family/c-pragma.h, we declare a pragma_handler which is a function 
> accepting cpp_reader as parameter.
> 
> I have changed this handler in order to accept a second parameter which 
> is a void *, allowing to give extra datas to the handler. I think this 
> data field might be of general use: we can have condition or data at 
> register time that we want to express in the handler. I guess this is a 
> common way to pass data to an handler function.

I find this patch interesting and useful (& not only for MELT).

A general coding rule in C seems to be that every time function can be
variably called thru indirect pointers (which can have several
different functions as value), they better take an extra data argument.
This is the case, in particular, inside Glib & GTK, inside the Linux
kernel, and on several other occurrences in GCC.

A use case of such pragma handlers with data for pragmas would be a
plugin which permit some messages to other channels than stdout/stderr
(e.g. other files, or a pipe, or the D-Bus, or a widget, or a web
service...). Then the same routine would handle 
   #pragma GCCPLUGIN message_to_file "foo"
and 
   #pragma GCCPLUGIN message_to_pipe "bar"
and the data pointer would be different (an fopen-ed or popen-ed
FILE*, or even an std::ostream& if the plugin is coded in C++). 


I am not authorized to ok the patch (I believe the changelog had some
typos), but I hope someone will review & ok it.

Regards




-- 
Basile STARYNKEVITCH         http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mine, sont seulement les miennes} ***

Reply via email to