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
where GtkDialogFlags is typedef'd to an enum and in
gtk_dialog_new_with_buttons() it is assumed that the coder
can combine flags.