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 8064119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:16:19+00:00 2026-06-05T11:16:19+00:00

I compile for LPC1114, a small ARM (actually Cortex) target. RAM is much more

  • 0

I compile for LPC1114, a small ARM (actually Cortex) target. RAM is much more limited than ROM. I use the latest Mentor (CodeBenchLite) GCC compiler (GCC 4.6.3). I have some constant objects that I’d like to have in ROM. As far as I understand the ffx object in the code below should end up in ROM (code), but instead it is placed in DATA.

class flop {
    public:
       int x;
       constexpr flop( int x ) : x(x){}
};

 extern constexpr flop ffx( 1 );

How can I convince the compiler to pre-compute the object and place it in ROM?

or maybe I should ask:

  • can I somehow expect the G++ compiler to generate ROMable data for ffx
  • if so, is my code correct for this
  • if so, for which G++ version is this supported (I use 4.6, maybe I need 4.7?)

=======================================

This bugzilla entry c++/49673 seems to indicate that mine is a known problem, probably fixed in GCC 4.7. Unfortunately I prefer to use the Mentor/CodeSourcery built, which is still at 4.6.3. So I guess for the time being I am stuck with the bug. 🙁

  • 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-05T11:16:20+00:00Added an answer on June 5, 2026 at 11:16 am

    Update #2: Test results with gcc 4.7.0

    This is indeed fixed in gcc 4.7.0. Your code produces the following assembler output:

        .file   "constexpr.cpp"
        .globl  _ffx
        .section .rdata,"dr"
        .align 4
    _ffx:
        .long   1
    

    which is what you probably want. Upgrading?

    I think you need a platform specific solution for this. See Locating code and data in memory (Scatterloading):

    Scatterloading allows you to partition an application into a number of separate code and data regions spread throughout the address map. The location of these regions can differ between load time and run time:

    1. Load Regions contain application code and/or data used by the application at power-on/load time (typically ROM).

    Instead of relying on gcc alone, try to make use of armlink as suggested in the link provided above.

    Update: I saw the gcc bug you’ve noted. LLVM/MinGW is equally hopeless. However, I’ve been playing around with GCC 4.6 and here’s something I think may help you:

    struct Data
    {
        int i;    
    };
    constexpr Data getData() { return Data{1}; }
    

    If instead of having a ctor, you have a constexpr function, and try to generate the assembler output, the output will typically be empty (no .data sections). And if you use this to initialize some variable (in global scope) as below:

    const Data foo = getData();
    

    you’d get an assembly as follows:

        .file   "constexpr.cpp"
        .section .rdata,"dr"
        .align 4
    __ZL3foo:
        .long   1
    

    (this is with g++ -std=c++0x -S command line). Does that work for you?

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

Sidebar

Related Questions

I want clang to compile my C/C++ code to LLVM bitcode rather than a
To compile my java app, I use from terminal: javac -cp commons-digester-2.1/commons-digester-2.1.jar:lucene-core-3.0.3.jar CollectionIndexer.java To
I compile my programm against javaee-api. But for Junit testing I must use a
I compile my own PHP, partly to learn more about how PHP is put
To compile my C++ code I use the -W flag, which causes the warning:
I compile my file with javac myfile.java But when I run myfile.class file with
I compile my C++ program to LLVM IR using the following command. clang++ -O4
Is it possible to compile a linux kernel(2.6) module that includes functionality defined by
When I try to compile this code: struct BasicVertexProperties { Vect3Df position; }; struct
if I compile (under G++) and run the following code it prints Foo::Foo(int). However

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.