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

--- Comment #5 from Rick Greer <rick at regreer dot net> ---
OK, now I get it.  The array of pointers is, indeed, static but the compiler is
trying to allocate the data that those pointers reference on the stack!  I was
confused by the fact that C++ lets me do this:

   void foo () { static char *bar[] = { (const char []){"xxx"} };

whereas C does not (of course, C++ allows stuff like:

    switch (x) { case "abc"[0]: ... }

as well).  C++ is assuming that 'const' implies static, which isn't necessarily
the case.  While the simplest way to implement 'const' data is to stick it at
the end of the protected code space, you could also have a function prologue
that allocates automatic 'const' data on an appropriate page boundary,
initializes it as indicated, and then asks the operating system to dink with
the page tables to make the data read-only.  Not the most efficient
implementation, perhaps, but pedantically more correct than what C++ actually
does!

What I was (unknowingly) looking for was a way of explicitly specifying a
literal's storage class.  Something like:

     (static char []) {"foo"}

which is, of course, syntactically bogus.

Thanks again for the enlightenment, sensei.

Reply via email to