N
Noah Roberts
I'm looking for ideas on approaches to dealing with a type of
problem...
Say you have a project with several thousands of lines of code that
uses a certain C API for GUI work (really doesn't matter which one, the
problem is across the board). You of course have much code in which
you are casting objects to void* in order that they can be passed
through the API into some callback function, where you will be casting
from void* back into whatever type you expect.
Here's where the fun comes in...
Much has changed in this code over the years and particular objects
that are commonly cast around have become quite large; there's a lot of
monolithic objects and superfluous inheritance that is causing
problems. You would like to split them up into different higherarchies
and interfaces so that functions that use some subset of the interface
for that object can just respond to a new interface that is composed of
that functionality. This ends up introducing MI into your code.
The question of what to cast to/from really came up a long time
ago...many years ago probably...but nobody really noticed because MI
wasn't an issue so things just kind of worked even though UB is all
over the place.
So you have tons of code that is rather careless about using
reinterpret_casts so as soon as you start changing things the way you
would like to things go up shit creek really fast. The compiler of
course won't tell you anything...you can't do an accurate cast at the
other side because the objects passed in have various differing
locations for their bases...
So, what would you do? I'm kind of at a loss as to how to go about
solving this. It doesn't help that the standard cast before I came
along and said it was bad was to use C-style casts...so finding
reinterpret_casts isn't going to be easy...
The big picture is actually quite a bit worse than what I am describing
but I'm not looking for consulting. What kind of things have people
done who've experienced something resembling the problem I find myself
in?
problem...
Say you have a project with several thousands of lines of code that
uses a certain C API for GUI work (really doesn't matter which one, the
problem is across the board). You of course have much code in which
you are casting objects to void* in order that they can be passed
through the API into some callback function, where you will be casting
from void* back into whatever type you expect.
Here's where the fun comes in...
Much has changed in this code over the years and particular objects
that are commonly cast around have become quite large; there's a lot of
monolithic objects and superfluous inheritance that is causing
problems. You would like to split them up into different higherarchies
and interfaces so that functions that use some subset of the interface
for that object can just respond to a new interface that is composed of
that functionality. This ends up introducing MI into your code.
The question of what to cast to/from really came up a long time
ago...many years ago probably...but nobody really noticed because MI
wasn't an issue so things just kind of worked even though UB is all
over the place.
So you have tons of code that is rather careless about using
reinterpret_casts so as soon as you start changing things the way you
would like to things go up shit creek really fast. The compiler of
course won't tell you anything...you can't do an accurate cast at the
other side because the objects passed in have various differing
locations for their bases...
So, what would you do? I'm kind of at a loss as to how to go about
solving this. It doesn't help that the standard cast before I came
along and said it was bad was to use C-style casts...so finding
reinterpret_casts isn't going to be easy...
The big picture is actually quite a bit worse than what I am describing
but I'm not looking for consulting. What kind of things have people
done who've experienced something resembling the problem I find myself
in?