Re: Fw: Re: [AD] messy allegro 5.0 stuff

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


On Fri, Jan 04, 2002 at 02:37:24PM +0100, Hein Zelle wrote:
> >    void al_read_key(int *unicode, 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;
> };

While it may look cleaner, structures could be a pain if they change
sizes, since they don't break the API directly, you later have to
care about programs using a structure with different sizes (doesn't
that remind you of the ugly .size field of every DirectX structure?)
Besides, the code could be like this:

void al_read_key(int *unicode, int *scancode)
{
   AL_ASSERT(unicode || scancode);
   if(unicode) *unicode = ...;
   if(scancode) *scancode = ...;
}

meaning that you can put NULL where you don't want to get a value.

-- 
 Grzegorz Adam Hankiewicz   gradha@xxxxxxxxxx   http://gradha.infierno.org/



Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/