Re: [AD] Global variables vs. Access functions

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


Guillermo Martínez Jiménez wrote:
...
I want to do a proposal about global variables. The old API has some
of them (key, screen, font, key_shifts, etc.). When I wrote
Allegro.pas I had a lot of problems with them and some should be
translated onto "pointers to pointers of something". The hardest ones
were the global arrays (key, fix_cos, fix_sin...). I don't know if
other ports (python, D...) had same problems but if the new API will
use access functions instead of global variables (you know "int
get_key_shift (void);" and "void set_key_shift (int);" instead of
"extern int key_shift;") they will be easer to port and I think it
will add more stability to the library (check bounds, values and other
possible problems).

Avoiding global variables might have made the D port slightly easier, because variables in DLL files are mangled differently from variables for static linking. And that's not handled in a very elegant way in D. No big deal, though.

Probably wouldn't matter much for new python wrappers, as the new ctypes module supports accessing variables in DLLs.

But in general, it seems that using functions instead has some advantages.




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