Ran into a problem in VS2013, and was asking HOW COULD THIS HAVE EVER WORKED?
A customer had the following macro in production.
(specifics have been changed)
#define IS_NONE( charPtr ) ( ( charPtr == "none" || charPtr == "N/A" ) ? TRUE : FALSE )
My problem was the code was crashing when a block named "none" was requested. The code should have identified a "none" block and skipped requesting the block. But it failed to do so?
I knew the customer code was running production in VS6.0, but was only crashing in VS2013.
The Answer is below.
The test case below builds in Visual Studio 6.0.
The default Visual Studio6.0 behavior is "Program Database with Edit and Continue". Turns out this enables STRING POOLING. So the compiler sweeps through and optimizes ALL compile time strings into a pool, and duplicate strings are ELIMINATED. So all literal definitions of "none" and "N/A" below will POINT TO THE SAME PHYSICAL ADDRESS. As a result the string compare appears to work.
Any dynamically created strings will fail to match, as their addresses will always be unique.
To get this test case to FAIL build it with "Program Database" in VS 6.0 (See screenshot below).
Below is an image of the test case passing. Note that all the string ADDRESSES are the same.
Built with "Program Database With Edit and Continue"
This is the test case failing, as one would expect for an incorrect Compare syntax.
Built with "Program Database"
Hopefully this will help others trying to figure out why VS6.0->Modern compiler ports appear to work on VS6.0 (1998 compiler) but fail with a modern compiler.