If the compiler loads the operands straight to VFP registers (needed because an actual floating-point computation is done), the above code will generate a SIGBUS. If the compiler loads the operands to integer registers first and then transfers them to the FPU, the code won't generate a SIGBUS. Optimisation can affect the result too. In my experiments, -O0 generally means that SIGBUS doesn't happen, since in this case floating-point operands are usually loaded to integer registers before being transferred to FPU registers.
(argh, hit "post" by accident)
This probably won't generate a fault, because only integer accesses are done to the target pointer in the generated code:
main () {
printf("%f\n", *(double *)((char *)main + 2));
}
This probably will (but it depends on compiler options, and on what code the compiler actually generates):
main () {
printf("%f\n", *(double *)((char *)main + 2) + *(double *)((char *)main + 6));
}
If the compiler loads the operands straight to VFP registers (needed because an actual floating-point computation is done), the above code will generate a SIGBUS. If the compiler loads the operands to integer registers first and then transfers them to the FPU, the code won't generate a SIGBUS. Optimisation can affect the result too. In my experiments, -O0 generally means that SIGBUS doesn't happen, since in this case floating-point operands are usually loaded to integer registers before being transferred to FPU registers.