C++ Logo

std-proposals

Advanced search

Re: [std-proposals] PROPOSAL: Reintroduce register — wise for developer-first decisions.

From: David Brown <david.brown_at_[hidden]>
Date: Tue, 22 Sep 2026 09:40:21 +0200
C++ already defines "asm" as a keyword, with almost no specified syntax
or semantics except to say it is an implementation-defined way to pass
information to an assembler. That's a good compromise, IMHO - there is
no attempt to define what "inline assembly" means or how it works, but
implementations at least know they can use the keyword "asm" for the
purpose.

Many compilers - gcc, clang, and others - support "register variables"
with a syntax like :

 register int foo asm("r10");

I don't think the "register" part is really necessary - it should be
realistic (and I say this without knowing anything about the internals
of gcc!) to use the same syntax without the "register" keyword if it is
ever repurposed in C++ for something incompatible.

So as things stand, there is already a way to get implementation-defined
specific register allocation that the OP wanted. At most, all the C++
standard needs is a note that "asm declaration" can be used as part of
other declarations. (At the same time, it should be changed to allow
anything inside the parentheses, not just a string-literal.)

As you say, it makes no sense to try to say what "asm" actually does in
the C++ standards - it cannot be described in terms of the abstract
machine. But it is feasible to be a little bit clearer on the preferred
syntax for implementation-specific "asm" extensions so that there is
minimal chance of conflicts later. And it could avoid "register"
entirely, rather than "re-introducing" it in some way.

David



On 21/09/2026 21:33, Sebastian Wittmeier via Std-Proposals wrote:
> The abstract machine does not have registers, especially not in a
> portable way.
>
> If you want named hardware registers, use an asm block.
>
> That would be an absolute mess to specify. You would have to specify all
> kind of theoretical side effects to avoid the as-if rule. Even for
> registers not used with normal C++ and implemented on a single hardware
> architecture.
>
> Perhaps an implementation could do it as non-standard extension. Like
> periphery registers on microcontrollers.
>
> But it does not belong into the standard.
>
> It is not compatible from a philosophical, technical, wording, practical
> level.
>
>
> -----Ursprüngliche Nachricht-----
> *Von:* Liam Graham via Std-Proposals <std-proposals_at_[hidden]>
> *Gesendet:* Mo 21.09.2026 14:09
> *Betreff:* [std-proposals] PROPOSAL: Reintroduce register — wise for
> developer-first decisions.
> *An:* std-proposals_at_[hidden];
> *CC:* Liam Graham <liamgraham_at_[hidden]>;
> Treat it like a storage class, not as a compiler hint
> Register int X["R8"]
> Or perhaps
> Register int X[0] where [N] is the register file index. The issue is
> calling conventions. But allow the developer to shoot themselves in
> the foot if they choose.
> #pragma register(RAX)
> [[register:RAX]]
> Etc etc
>
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>
>
>

Received on 2026-09-22 07:40:31