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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T14:49:24+00:00 2026-06-18T14:49:24+00:00

I work with embedded stuff, so, I use special C compiler C30 for MCUs.

  • 0

I work with embedded stuff, so, I use special C compiler C30 for MCUs. I’m confused about its behavior with temporary structures.

But, maybe I don’t know something, and it’s intended behavior?

Consider little code:

typedef struct {
   int a;
   int b;
} T_TestStruct1;

void test1(T_TestStruct1 *p_test_struct)
{
   /* do something */
}

And these calls to test1() :

void some_function()
{

   {
      T_TestStruct1 par = {
         .a = 1,
         .b = 1,
      };
      test1(&par);
   }

   {
      T_TestStruct1 par = {
         .a = 2,
         .b = 2,
      };
      test1(&par);
   }

}

Everything is OK here: just one instance of T_TestStruct1 is allocated in the stack. But I like to use shorter expressions:

void some_function()
{
   test1(&(T_TestStruct1){
      .a = 1,
      .b = 1,
      });

   test1(&(T_TestStruct1){
      .a = 2,
      .b = 2,
      });
}

Then, both structures {.a = 1, .b = 1} and {.a = 2, .b = 2} are allocated in the stack. But, in my opninion, they should not be. Only one instance is actually needed.

Just by chance, I tried that:

void some_function()
{
   {
      test1(&(T_TestStruct1){
         .a = 1,
         .b = 1,
         });
   }

   {
      test1(&(T_TestStruct1){
         .a = 2,
         .b = 2,
         });
   }
}

Result is the same.

So, is it intended behavor, or is it a bug in the compiler?

  • 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-18T14:49:26+00:00Added an answer on June 18, 2026 at 2:49 pm

    Actually I don’t see the benefit of the expression causing you troubles. It makes the code just less readable.

    But apart from that: You can’t predict whether the compiler creates a stackframes including two instances of the structure or not. This is up to the compiler and his optimization engine. In case you really need control about the allocation of memory here and you really need to optimize, I’d suggest to allocate this variable once and explicitly reuse it for both calls, leaving a comment why you do it like this.

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

Sidebar

Related Questions

I've started learning embedded and its 2 main languages (c and c++). But I'm
I work on embedded device with linux on it. I want to use DHCP
The media player embedded code work only in IE.How I can do it able
I'm responsible for some embedded software that has to work with a customer's proprietary
Hi I am having trouble getting an embedded js file to work. I have
I am setting up embedded forms in my rails app. This does not work
I'm an Ubuntu Linux user and I use Win XP only for my work
I'm starting to work with Embedded Linux and I've got a LPC313x based board
I'm starting work on a new embedded Linux project. The project will consist of
I'm using IAR Embedded Workbench for ARM (ARM7TDMI-S) and the majority of my work

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.