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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:21:28+00:00 2026-05-23T16:21:28+00:00

Can someone explain where and how string constants are stored by the compiler and

  • 0

Can someone explain where and how string constants are stored by the compiler and how they’re accessed by the runtime?

  • 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-05-23T16:21:29+00:00Added an answer on May 23, 2026 at 4:21 pm

    First the obligatory: you should shouldn’t care how the compiler does this; anything based on how the compiler does this is a dangerous reliance on something that is not guaranteed and can change based on how the compiler optimizes. Do not write code based on this. Really. OK, we’ve got that out of the way.

    Say you have code like this:

    NSString *something = @"I'm a constant";
    

    The compiler will generate this:

        .section    __TEXT,__cstring,cstring_literals
    l_.str:                                 ## @.str
        .asciz   "I'm a constant"
    

    As you see, it’s stored in the __TEXT section, along with your code, as a cstring literal. Over in __DATA, it’ll store the constant CFString itself like this:

        .section    __DATA,__cfstring
        .align  4                       ## @_unnamed_cfstring_
    L__unnamed_cfstring_:
        .quad   ___CFConstantStringClassReference
        .long   1992                    ## 0x7c8
        .space  4
        .quad   l_.str
        .quad   14                      ## 0xe
    

    First, it stores the CFType (CFConstantStringClassReference). Then internal information about the string (is it immutable, how is it deallocated, is it unicode, etc), a pointer to the cstring, and a length (14). If you want the details on the structure, pull down the CF sources from opensource.apple.com and look at CFString.c. It explains the whole “internal information” field pretty well. (Pull them from Snow Leopard; Apple doesn’t publish them as part of iOS, but they’re the same.)

    A second constant string would look like this, just to demonstrate how the symbol naming is done for the assembler.

        .section    __TEXT,__cstring,cstring_literals
    l_.str2:                                ## @.str2
        .asciz   "%@"
    
        .section    __DATA,__cfstring
        .align  4                       ## @_unnamed_cfstring_3
    L__unnamed_cfstring_3:
        .quad   ___CFConstantStringClassReference
        .long   1992                    ## 0x7c8
        .space  4
        .quad   l_.str2
        .quad   2                       ## 0x2
    

    If you want to get a better handle on this, just ask Xcode to generate the assembly for a simple file and see what it does. Oh, and of course you should never use this information because gcc could change at any time. But it’s great stuff to dig into.

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

Sidebar

Related Questions

Can someone explain what exactly the string 0 but true means in Perl? As
Can someone explain to me why my code: string messageBody = abc\n + stringFromDatabaseProcedure;
Can someone explain to me why these comparisons work they way the do. I
I'm really confused here, can someone explain this to me? request: http://example.com/test.php?var=String's $a =
Can someone explain to me why in .NET I would write String.IsNullOrEmpty(str) instead of
Can someone explain to me why ServletRequest.getParameterMap() returns type Map<String, String[]> ServletRequest.getParameter() just returns
Can someone explain this weird behavior of python re? Obviously the string 'test' does
Can someone explain this one to me: http://jsperf.com/string-concatenation-1/2 If you're lazy, I tested A)
Can someone explain to me why my call to malloc with a string size
Can someone explain why POST call to the following actions is ambiguous? They 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.