S
Servé Laurijssen
Recently, I found myself in the following situation:
There is library software written in C which declares some externals like:
struct METER m1;
struct METER m2;
in different sourcefiles and I have no control over these sources.
Then there's functions that operate on these meters and will generate an
event which passes a METER * to identify which meter has been changed.
static void OnChangemeter(struct METER *m)
{
if (m == &m1) ...
if (m == &m2) ...
}
Now the comparison of these pointers is UB in C but in this case it's the
only way to do it. What would you do in such a situation when you work on a
project that has to be finished shortly?
Would you jump high and low to get the library writers to change this into
non UB code or would you continue knowing that it works on the current and
future platforms that this code will run on?
There is library software written in C which declares some externals like:
struct METER m1;
struct METER m2;
in different sourcefiles and I have no control over these sources.
Then there's functions that operate on these meters and will generate an
event which passes a METER * to identify which meter has been changed.
static void OnChangemeter(struct METER *m)
{
if (m == &m1) ...
if (m == &m2) ...
}
Now the comparison of these pointers is UB in C but in this case it's the
only way to do it. What would you do in such a situation when you work on a
project that has to be finished shortly?
Would you jump high and low to get the library writers to change this into
non UB code or would you continue knowing that it works on the current and
future platforms that this code will run on?