Re: Fw: Re: [AD] messy allegro 5.0 stuff |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
Sven Sandberg wrote:
> Yes, and this seems much cleaner than having to mask out the value, but
> how should it be done? Probably it would have to be something like
>
> void al_read_key(int *unicode, int *scancode);
> or
> int al_read_key(int *scancode);
I personally dislike parameter lists like the above where you have
to provide 2 storage variables for return values, when you normally
will be using only 1 at a time. Is it not possible to do something
like the following? (forget name clashes for a minute)
struct AL_KEY
{
int unicode;
int scancode;
};
struct AL_KEY al_read_key()
{
struct AL_KEY k;
/* fill in values */
return k;
}
If you insist that passing a struct over the stack is ugly (which it
is, I guess, but with 2 integers I don't think it's _that_ bad) we
could always go for
void al_read_key(AL_KEY *);
or even
int al_read_key(AL_KEY *);
where the latter can return error values if required. I personally
prefer the first option (returning a struct) but passing a struct as
argument will do as well. IMHO, this makes it easier to use the
function as you only need to define one local variable. Returning a
struct also make the following possible:
if (al_read_key().scancode == KEY_BLADIEBLA)
{
...
}
Hein Zelle
>-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-<
Hein Zelle hein@xxxxxxxxxx
http://www.icce.rug.nl/~hein
>-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-<