Can an integer be NaN in C++?

Viewed 35516

Can I set an int to NaN? If yes, then how can I check if an int is NaN or not?

5 Answers

I think the most proper API to handle failures is to return a second integer error code in your api like:

int myfunc(args, int* realReturn);

The returned int is an error code.

The previous output is passed as a pointer in calling code:

int myInt;
if (myFunc(args, &myInt) != 0) {
//handle error
}
Related