Question: I wrote a simple cooperative multi-threading library. Currently I always save and restore the fpu state with `fxsave` / `fxrstor` when switching to a new context. But is this necessary in the cdecl calling convention?

As a simple example:

```
float thread_using_fpu(float x)
{
    float y = x / 2; // do some fpu operation
    yield();         // context switch, possibly altering fpu state.
    y = y / 2;       // another fpu operation
    return y;
}

```

May the compiler make any assumptions about the FPU state after the call to `yield()`?

Answer: 
You should check for `my_callback == 0` since it's a function pointer.

---

Moreover, the second option you are thinking of:

```
&my_callback == 0

```

is the **address** and you will even been warned by the compiler:

```
warning: the comparison will always evaluate as ‘false’ for the address of ‘my_callback’ will never be NULL [-Waddress]
  if(&my_callback == 0)
                  ^

```

---

[Is NULL always zero in C?](https://stackoverflow.com/questions/9894013/is-null-always-zero-in-c)
Remember that the type of the variable is a function *pointer*, so you can compare it directly against `NULL` or `0`.

It might depend on your coding convention and style preferences, but I tend to use the pointer as the boolean value itself:

```
if (my_callback) {
    // Do the thing
}

```