Allin,
thanks for clarifications.
I know about the power-of-two technique of combining flags and use it myself,
but I did not know that enum in C accepts values not on the list - C++ does not
(which seems logical: if you say the arg. comes from a list, you reject values
not on the list).
Anyway, the point is that if one changed this from enum to int/unsigned, it
would work in both C and C++.
Michal
On 23.08.2011 17:43, Allin Cottrell wrote:
On Tue, 23 Aug 2011, Michal Kaut wrote:
> I am trying to learn libgretl and have one question: in
> gretl_VAR(), the description of the 4th parameter (opt) says
> "if includes OPT_R, ..", suggesting that one can combine
> several flags. Also the source code seems to expect this,
> having checks of type "opt & flag".
> However, the parameter is of type gretlopt, which is an enum
> - so that I have to use exactly one number from the list (at
> least in C++, not sure about C).
>
> Shouldn't the parameter be int, so that one could add
> several values from gretlopt - or did I misunderstood
> something, as usual?
In C you can use an enum as is done in libgretl -- allowing
for compositing values -- provided of course that the
enumeration contants are defined such that they do not collide
with each other. This is achieved in libgretl.h by defining
the constants as successive powers of 2:
OPT_A = 1 << 0,
OPT_B = 1 << 1,
OPT_C = 1 << 2,
and so on. This is a pretty standard C idiom. See for example
its use in GTK at
http://developer.gnome.org/gtk/2.24/GtkDialog.html ,
where GtkDialogFlags is typedef'd to an enum and in
gtk_dialog_new_with_buttons() it is assumed that the coder
can combine flags.
Allin Cottrell
_______________________________________________
Gretl-users mailing list
Gretl-users(a)lists.wfu.edu
http://lists.wfu.edu/mailman/listinfo/gretl-users