I inherited a large application that was originally written in C (but at the same time a lot of C ++ was added to it). Due to historical reasons, the application contains many pointers to emptiness. Before starting to suffocate, let me explain why this was done.
The application contains many different data structures, but they are stored in "universal" containers. Currently, I would use STL template containers for it, or I would give all data structures a common base class so that the container can store pointers in the base class, but in [good?] Old C-days, the only solution was to draw a struct-pointer to void pointer.
In addition, there is a lot of code that works on these void pointers, and uses very strange C constructs to emulate polymorphism in C.
Now I am processing the application and trying to get rid of void pointers. Adding a common base class to all data structures is not so difficult (several days of work), but the problem is that the code is full of constructs, as shown below.
This is an example of how data is stored:
void storeData (int datatype, void *data);
This is an example of how data is retrieved again:
Customer *myCustomer = (Customer *) fetchData (TYPE_CUSTOMER, key);
I really want to replace all void pointers with some kind of smart pointer (with reference counting), but I can't find a trick to automate (or at least) help me get rid of all casts and void pointers.
Any tips on how to find, replace, or in any way interact with these conversions?
c ++ c casting void-pointers
Patrick
source share