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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:44:04+00:00 2026-06-17T09:44:04+00:00

For example when I have: const char mesg [] = Hello World; it is

  • 0

For example when I have:

const char mesg [] = "Hello World";

it is directly put in the .rodata but when I have:

const char* mesg = "Hello World";

it is put directly in .rodata.str1.4

What is the difference between them and why we use .rodata.str1.4 when we use the pointer ?

  • 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-17T09:44:05+00:00Added an answer on June 17, 2026 at 9:44 am

    I did a couple of experiments, it looks like the compiler places strings in special sections in object files. The interesting thing happens when the binary is compiled, the strings end up in .rodata as expected. Further experiments show that what happens is that if you have the same string in different objects they get unified into the same string in the resulting binary.

    So I’d suspect that the reason for this is that the compiler wants to give the linker some information about the read only data other than “it’s read-only”, so that the final link can make more intelligent decisions about how to handle it, including deduplication.

    $ cat foo.c
    const char *
    fun(int i)
    {
            const char *foo = "foofoo foo foo foo";
        const char *bar = "barbar bar bar bar";
        return i ? foo : bar;
    }
    $ cat bar.c
    #include <stdio.h>
    extern const char *fun(int);
    
    int
    main(int argc, char **argv)
    {
        const char *foo = "foofoo foo foo foo";
    
        printf("%s%s\n", foo, fun(1));
        return 0;
    }
    $ cc -c -O2 foo.c
    $ cc -c -O2 bar.c
    $ objdump -s foo.o
    [...]
    Contents of section .rodata.str1.1:
     0000 62617262 61722062 61722062 61722062  barbar bar bar b
     0010 61720066 6f6f666f 6f20666f 6f20666f  ar.foofoo foo fo
     0020 6f20666f 6f00                        o foo.
    [...]
    $ objdump -s bar.o
    [...]
    Contents of section .rodata.str1.1:
     0000 666f6f66 6f6f2066 6f6f2066 6f6f2066  foofoo foo foo f
     0010 6f6f0025 7325730a 00                 oo.%s%s..
    [...]
    $ cc -o foobar foo.o bar.o
    $ objdump -s foobar
    [...]
    Contents of section .rodata:
     400608 01000200 00000000 00000000 00000000  ................
     400618 62617262 61722062 61722062 61722062  barbar bar bar b
     400628 61720066 6f6f666f 6f20666f 6f20666f  ar.foofoo foo fo
     400638 6f20666f 6f002573 25730a00           o foo.%s%s..
    [...]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string as const char *str = Hello, this is an example
Why does: const char example; (uint64*)example have a value of 140734799798420 and *(uint64*)example have
For example, I have a constructor like myClass(const char* name); Can it be like
I have a const char const char example[] = \x4D\x5A\xE8\x00\x00\x00\x00\x5B\x52\x45\x55\x89\xE5\x81\xC3; and DWORD* example2 =
Say I have this example: char const * const foo( ){ /* which is
I have const binary data that I need insert to buffer for example char
Let's say I have a bunch of well-known values, like this (but const char
I have several simple C++ classes, for example: class Audio { public: Audio(const char
I have an really simple example of array of const char's and one function
For example, does Apple provide NSString * const kCFBundleDisplayName somewhere? Or do I have

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.