What does—or did—“volatile void function( … )” do?

后端 未结 3 1299
抹茶落季
抹茶落季 2021-02-12 09:51

I\'ve seen How many usage does "volatile" keyword have in C++ function, from grammar perspective? about use of the volatile keyword on functions, but there was no clea

3条回答
  •  不知归路
    2021-02-12 10:17

    The C99 standard says this in §6.7.3/3:

    The properties associated with qualified types are meaningful only for expressions that are lvalues.114)

    114) The implementation may place a const object that is not volatile in a read-only region of storage. Moreover, the implementation need not allocate storage for such an object if its address is never used

    §6.2.5/19 says:

    The void type comprises an empty set of values; it is an incomplete type that cannot be completed.

    And §6.3.2.1/1 says:

    An lvalue is an expression with an object type or an incomplete type other than void;53) [...]

    Hence, void is not an lvalue, so the type qualifiers (const, volatile, and restrict) are not meaningful for expressions of type void. So, in any C99-compliant compiler, const void and volatile void are meaningless (although pointers to const void and const volatile are meaningful).

    Furthermore, the constraints of §6.9.1/3 disallow a function to return a qualified type of void:

    The return type of a function shall be void or an object type other than array type.

    Since this is a constraint, a conforming compiler must issue a diagnostic (§5.1.1.3/1). So a function returning volatile void is not allowed in C99.

    As for what volatile void may have used to do, I have no idea and can't really speculate. The AES code you're looking at probably just has old cruft that never got cleaned up, I'd guess.

提交回复
热议问题