Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8939355
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:48:22+00:00 2026-06-15T10:48:22+00:00

Given following definition of global (or static local) variable: static const <type>* const ptr

  • 0

Given following definition of global (or static local) variable:

static const <type>* const ptr = {&var1, &var2, ...};

, may I rely upon the fact that both ptr and data in initializer list will be placed to separate read-only section of generated object file (i.e. it will not be placed to .data or similar sections containing non-const variables) ?

Question relates only to gcc c/c++ compiler behavior common to all architectures/platforms (at least those of them where read-only memory exists). It doesn’t imply any platform, processor, OS, linker, start-up runtime, libraries, etc.

Please, don’t ask me what I’m going to do. I know what I’m doing. If the information I provided are not enough for answer then issue has to be considered as xxx-specific and generic answer is “No”. I have already read questions-answers where this subject was mentioned very close:

Impact of the type qualifiers on storage locations
How is read-only memory implemented in C?
Does "const" just mean read-only or something more?
Why does compiler allow you to "write" a const variable here?
GCC C++ (ARM) and const pointer to struct field
memcpy with destination pointer to const data

But I didn’t found assured and direct answer.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T10:48:23+00:00Added an answer on June 15, 2026 at 10:48 am

    According to the stackoverflow thread Where are constant variables stored in C? It is implementations specific. And personally I would not even rely on the thought that all GCC ports are implemented the same way. That’s why for example the AVR port introduced a “progmem” attribute.

    So according to your

    Don’t ask me what I’m doing, if there is not enough information, the answer is “no”

    attitude, I’d say here: The answer is “no” there is no portable way to guarantee something like that. In fact even if you instruct the compiler and the linker to place it in something like a “readonly section”. If this section lies in RAM, who will prevent write access to this section?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following type definition: type 'a range = Full | Range of ('a
Given the following simple BST definition: data Tree x = Empty | Leaf x
Given the following Oracle (10g) package definition: create or replace PACKAGE foo AS bar
Given this following table definition: TRUCK (TruckNum, TruckType, TypeDesc, TruckMiles, DatePurchased, TruckSerialNum, BaseCity, BaseState,
I have a table FOO with the following definition: id INTEGER, type INTEGER, data
Given the following C++ code: struct foo { // Some definition with copy constructor.
We have a WSDL which contains the following type definition: ... <xsd:complexType name=OrderItem> <xsd:all>
given the following class definition: public class Order { public IProduct Product {get;set;} }
Given the following entity (some columns omitted from this long definition for brevity): @Table(name
Given a class with the following definition: public class MyTestClass { public int ValueA

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.