Menu

#3 misuse of static variable in library cod

open
nobody
None
5
2002-03-01
2002-03-01
Semenov
No

Hi!

When I went through the source code, I found a lot of
misuse of static variables, in face according to rules
for library building, one must not use static
variables in the library source code.
Somehow it works with gcc, but I guess it hides some
bugs, that use this space, but when it come to
CodeWarrior it starts crashing.
I propose to pass all static variables as a structure
set thru TableEntry variable which can be accessed by
SysLibTblEntry(LibRef), that doesn't require locking
the table variable. The same way it can be accessed in
the library code.

struct constants
{
char *data1 = ...
char *data2 = ...
bool data3 = ...
char *data4 = ...
....
}

struct constants const_data;
const_data.data1 = table1
const_data.data2 = ....
...
SysLibTblEntryPtr libEntryP = SysLibTblEntry(libRef);
libEntryP->globalsP = (void*) &const_data;

in the libarary you can use:

((struct constants*)SysLibTblEntry(libRef))->data1;

That's it

Best Regards
Dmytry

Discussion


Log in to post a comment.