Can an implementation consider hints as actual statements?

前端 未结 2 1635
梦如初夏
梦如初夏 2021-01-27 01:56

In C, the register storage qualifier is an hint to the implementation that such identifier should be accessed as fast as possible (e.g. stored in a CPU reg

2条回答
  •  伪装坚强ぢ
    2021-01-27 02:32

    It is allowed to do it as long as it doesn't prevent well-formed programs from compiling or affects the observed behavior as specified in the standard in any way.

    The standard already forbids taking the address or alignment of an object declared with the register specifier, so that part wouldn't be a problem. A trickier case would be if you declare more objects with register than there are available registers. Unless the implementation still allows spilling for register objects (temporarily moving values from registers to e.g. the stack, and back), then this would be a case where the implementation would fail to compile a program that's conformant according to the standard.

提交回复
热议问题