Ist das keyword "register" Teil des C++ Standards oder compilerspezifisch?



  • Und macht es heute bei modernen Compilern überhaupt noch Sinn?

    Beispiel:

    register int i;

    Bedeutet:
    i wird, sofern der compiler dem register Keyword folgt, im Register der CPU gehalten



  • Ich glaub das kann jeder Compiler ignorieren, weil er sowieso besser weiß was in register soll.


  • Mod

    Das ist vom Standard garantiert, dass es das Schlüsselwort gibt. Was es macht, ist aber vielleicht nicht das was du denkst:

    C++ Standard schrieb:

    A register specifier has the same semantics as an auto specifier together with a hint to the implementation that the
    object so declared will be heavily used. [ Note: the hint can be ignored and in most implementations it will be ignored if
    the address of the object is taken. — end note ]

    edit: Das ist aus dem alten Standard, wo auto noch eine andere Bedeutung hatte. Im neuen Standard steht daher nur, dass ein register-Objekt automatische storage duration hat und dass man diesen Effekt auch hätte, wenn man gar nichts schreibt. Auserdem ist die Benutzung als Compilerhinweis deprecated.



  • SeppJ schrieb:

    Das ist vom Standard garantiert, dass es das Schlüsselwort gibt. Was es macht, ist aber vielleicht nicht das was du denkst:

    C++ Standard schrieb:

    A register specifier has the same semantics as an auto specifier together with a hint to the implementation that the
    object so declared will be heavily used. [ Note: the hint can be ignored and in most implementations it will be ignored if
    the address of the object is taken. — end note ]

    edit: Das ist aus dem alten Standard, wo auto noch eine andere Bedeutung hatte. Im neuen Standard steht daher nur, dass ein register-Objekt automatische storage duration hat und dass man diesen Effekt auch hätte, wenn man gar nichts schreibt. Auserdem ist die Benutzung als Compilerhinweis deprecated.

    Thx, dann lasse ich es in Zukunft weg.



  • Im neuen Standard(C++1) heist es:

    2
    The register specifier shall be applied only to names of variables declared in a block (6.3) or to function parameters (8.4). It specifies that the named variable has automatic storage duration (3.7.3). A variable declared without a storage class-specifier at block scope or declared as a function parameter has automatic storage duration by default.

    3
    A register specifier is a hint to the implementation that the variable so declared will be heavily used. [Note:The hint can be ignored and in most implementations it will be ignored if the address of the variable is taken. This use is deprecated (see D.2). — end note]


Anmelden zum Antworten