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

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


Hein Zelle writes:
>>    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.

Why not:

	al_read_key(int *unicode, int *scancode);

Plus provide two helper functions for the common case where you
only care about a single value:

	int al_read_unicode()
	{
		int ret, nowhere;
		al_read_key(&ret, &nowhere);
		return ret;
	}

	int al_read_scancode()
	{
		int nowhere, ret;
		al_read_key(&nowhere, &ret);
		return ret;
	}

Passing and returning structures is a bad idea in terms of binary
compatibility, as this is one area where different compilers
(and in some cases even the same compiler with different optimisation
settings) can decide to generate quite different calling conventions.
Even though they agree on how to call most types of functions, gcc vs.
MSVC vs. LCC vs. BCC vs. Watcom tend to use different methods for 
structures. This is a major part of why C++ compatibility is far worse 
than C, as C++ code is more likely to be passing and returning a lot 
of objects, and relying on the compiler to make this efficient, where 
C coders would be explicitly passing pointers to the structure in
question.


-- 
Shawn



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