Force crash/exception on NaN assignment in C/C++

69 views Asked by At

I often have subtle bugs or crashes in my C/C++ program when my code is dealing with NaN floats. Usually when this happens the program crashes in some unexpected place, for example at an array indexing like this array[int(some_float) - 1]. I then have to spend a lot of time chasing the reason for such a problem, identifying that some_float is NaN and looking at all the places where it might have been assigned to NaN.

Is there a way to force the compiler to crash early at exact moment and place where it assigned something to NaN? Since even assigning to NaN is a failed state for my program.

0

There are 0 answers