Research project here. In my C++ library, I am including C files:
#include "aprogram.c"
which I execute symbolically by overloading (almost) all operators.
I have to be able to detect (condition) ? this : that
and extract condition
, this
and that
for usage in my symbolic execution library. However, SO 1, SO 2 and SO 3 amongst others already helped me realise that ?:
cannot be overloaded.
- Is there any way for me to forcibly overload
?:
anyways? - Can I change all
?:
statements in my included C file into ifelse-statements without actually changing the file?
Macros were added to the C compiler in the 1970’s to simplify compiler design. Macros are processed by the ‘C Pre-processor’. Unfortunately this pre-processor is naive and does little more than text substitution. The generated code is often unnecessarily complicated, difficult to view (use –E or –P compile option) and hard to debug. Nowadays you should use the compiler to process all of your code (the pre-processor is usually limited to #includes and conditional compilation).
Unfortunately Bjarne Stroustrup decided not to allow you to overload ?: ternary – not for any deep technical reason, but because it was the only tertiary operator and he felt the effort in modifying the compiler was not justified.
According to the C++ standard you are not permitted to overload ?: The best you can do is use C macros (but this can lead to horrible code).