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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:51:58+00:00 2026-05-26T18:51:58+00:00

In C (NOT C++), I am trying to create two string tables that contain

  • 0

In C (NOT C++), I am trying to create two string tables that contain the same values, but have the values sorted in two different ways. And I don’t want the strings to be duplicated in memory.

Basically, I want to do the following. Except according to gcc, it fails because “initializer element is not constant” in the second array initialization. Is there some way around this problem? Preferably without saying “oh, well the compiler should optimize it to do what you want”?

static const char * monthNames[] = {
  "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};


/******** 
 * Month table sorted for O(log N) string lookup
 */
static const char * monthSortedKeys[]= {
  monthNames[3],          /* Apr */
  monthNames[7],          /* Aug */
  monthNames[11],         /* Dec */
  monthNames[1],          /* Feb */
  monthNames[0],          /* Jan */
  monthNames[6],          /* Jul */
  monthNames[5],          /* Jun */
  monthNames[2],          /* Mar */
  monthNames[4],          /* May */
  monthNames[10],         /* Nov */
  monthNames[9],          /* Oct */
  monthNames[8]           /* Sep */
};

Clarification: I know how to do this with a loop. I’m trying to figure out how to do it at compile time.

Another Update: I just compiled this as C++ (g++) and it works. But again, I’m looking for the C 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-05-26T18:51:59+00:00Added an answer on May 26, 2026 at 6:51 pm

    Example code snippet:

    static const char
        JAN[] = "Jan",
        FEB[] = "Feb",
        // ...
        DEC[] = "Dec";
    
    static const char *const monthNames[] = {
      JAN, FEB, /* ... */ DEC
    };
    
    static const char *const monthSortedKeys[]= {
        /* APR, ... */ DEC, /* ... */ FEB, JAN /* ... SEP */
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to UNION two tables with the same fields to create a
I'm trying to create a rails web app that does not use ActiveRecord framework
I'm trying to create a simple search page, but I'm not 100% sure how
I am trying to create virtual desktop. I complete successfully.But i am not able
I'm not sure how to describe this but I'm trying to create a base
Hey! I am not trying to push my luck here but I have another
Trying to create Database as follows: USE Master GO IF NOT EXISTS(SELECT [Name] FROM
I am trying to create a blog using blogspot. It seems it is not
I am trying to create a customized UISearchBar. I am not able to find
I'm trying to understand cocoa bindings, but I found a problem that I'm really

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.