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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T08:33:28+00:00 2026-05-15T08:33:28+00:00

I get an error on line 6 (initialize my_foo to foo_init) of the following

  • 0

I get an error on line 6 (initialize my_foo to foo_init) of the following program and I’m not sure I understand why.

typedef struct foo_t {
    int a, b, c;
} foo_t;

const foo_t foo_init = { 1, 2, 3 };
foo_t my_foo = foo_init;

int main()
{
    return 0;
}

Keep in mind this is a simplified version of a larger, multi-file project I’m working on. The goal was to have a single constant in the object file, that multiple files could use to initialize a state structure. Since it’s an embedded target with limited resources and the struct isn’t that small, I don’t want multiple copies of the source. I’d prefer not to use:

#define foo_init { 1, 2, 3 }

I’m also trying to write portable code, so I need a solution that’s valid C89 or C99.

Does this have to do with the ORGs in an object file? That initialized variables go into one ORG and are initialized by copying the contents of a second ORG?

Maybe I’ll just need to change my tactic, and have an initializing function do all of the copies at startup. Unless there are other ideas out there?

  • 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-15T08:33:29+00:00Added an answer on May 15, 2026 at 8:33 am

    In C language, objects with static storage duration have to be initialized with constant expressions, or with aggregate initializers containing constant expressions.

    A “large” object is never a constant expression in C, even if the object is declared as const.

    Moreover, in C language, the term “constant” refers to literal constants (like 1, 'a', 0xFF and so on), enum members, and results of such operators as sizeof. Const-qualified objects (of any type) are not constants in C language terminology. They cannot be used in initializers of objects with static storage duration, regardless of their type.

    For example, this is NOT a constant

    const int N = 5; /* `N` is not a constant in C */
    

    The above N would be a constant in C++, but it is not a constant in C. So, if you try doing

    static int j = N; /* ERROR */
    

    you will get the same error: an attempt to initialize a static object with a non-constant.

    This is the reason why, in C language, we predominantly use #define to declare named constants, and also resort to #define to create named aggregate initializers.

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

Sidebar

Related Questions

When trying to validate my site, I get the following error: Line 188, column
When I launch my emulator, I get the following error: invalid command-line parameter: Android
With include('basemodel.php'); I get Fatal error: Class 'BaseModel' not found in C:\xampp\htdocs\allsides\account\model.php on line
I get an error on line 14 of the below: using System; using System.Collections.Generic;
I get the error: Msg 2714, Level 16, State 1, Line 16 There is
i use this line of code : [self parseXMLFileAtURL:url]; And i get this error
Here is the error I get ArgumentError in External_articles#show Showing app/views/external_articles/show.html.erb where line #3
I run mvn install in command line and get stuck by below error. Caused
Why do I get error in this code?Even if i do not link but
I get error: ORA-06575: Package or function GET_CONC_NAMES is in an invalid state When

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.