public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/104514] New: add feature to create a pointer to a fixed address as constexpr
@ 2022-02-12 14:47 goswin-v-b at web dot de
  2022-02-12 21:55 ` [Bug c++/104514] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: goswin-v-b at web dot de @ 2022-02-12 14:47 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104514

            Bug ID: 104514
           Summary: add feature to create a pointer to a fixed address as
                    constexpr
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: goswin-v-b at web dot de
  Target Milestone: ---

In the embedded and micro controller world memory mapped registers are very
common. They can be declared as external object and fudged in using linker
scripts, which prevents a lot of optimizations. Or they can be declared as
pointers, in the most reduced form like this:

    int *p = (int*)0x12345678;

My problem now is that this isn't a constexpr and can't be used in any
constexpr code:

    foo.cc:1:20: error: ‘reinterpret_cast’ from integer to pointer
        1 | constexpr int *p = (int*)0x12345678;
          |                    ^~~~~~~~~~~~~~~~

While this is the right thing in general there should be a way to allow this
special case. A way to tell the compiler that an object exists at a fixed
address and still be a constexpr.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2022-02-15  8:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-12 14:47 [Bug c++/104514] New: add feature to create a pointer to a fixed address as constexpr goswin-v-b at web dot de
2022-02-12 21:55 ` [Bug c++/104514] " pinskia at gcc dot gnu.org
2022-02-13 12:06 ` redi at gcc dot gnu.org
2022-02-13 22:44 ` pinskia at gcc dot gnu.org
2022-02-14  3:03 ` pinskia at gcc dot gnu.org
2022-02-14 11:57 ` redi at gcc dot gnu.org
2022-02-15  8:27 ` q.gcc@rsn-tech.co.uk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).