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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T21:12:40+00:00 2026-05-13T21:12:40+00:00

This code has an interesting bug: some_struct struct_array1[10] = {0}; some_struct struct_array2[10] = {0}

  • 0

This code has an interesting bug:

some_struct struct_array1[10] = {0};
some_struct struct_array2[10] = {0}
int i;

for (i = 0; 
     i < sizeof(struct_array1) / sizeof(struct_array1[0]); 
     struct_array1[i].value = struct_array2[i++].value = 1)
    ;

For most compilers, the above code results in setting the “value” field of all structs in the respective arrays to 1.
However, for one specific compiler (let’s call it xcc), the structs in struct_array1 are NOT initialized correctly. The “value” field is set to 0 for all structs, which kind of surprised me.

The following code snippet works as expected on all compilers:

for (i = 0; 
     i < sizeof(struct_array1) / sizeof(struct_array1[0]); 
     i++)
{
    struct_array1[i].value = struct_array2[i].value = 1;
}

Now, am I completely off here, or does the offending compiler “xcc” simply display a bug?

I can’t find anything that displays implementation-specific behavior in the first code snippet; from what I understand the postfix incrementation should have precedence over the assignments, and the assignments should be evaluated right-to-left. There should be nothing wierd with the first code snippet, except that it’s a tad unreadable.

  • 1 1 Answer
  • 1 View
  • 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-13T21:12:40+00:00Added an answer on May 13, 2026 at 9:12 pm

    You have invoked undefined behaviour, because it modifies i and also fetches its value for a purpose other than calculating the new value, without an intervening sequence point.

    The relevant part of the C99 standard is this clause in section 6.5:

    Between the previous and next sequence
    point an object shall have its stored
    value modified at most once by the
    evaluation of an expression.
    Furthermore, the prior value shall be
    read only to determine the value to be
    stored.

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

Sidebar

Ask A Question

Stats

  • Questions 508k
  • Answers 508k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use a normal button instead of submit for your login… May 16, 2026 at 4:17 pm
  • Editorial Team
    Editorial Team added an answer The full current URL can be found in window.location.href the… May 16, 2026 at 4:17 pm
  • Editorial Team
    Editorial Team added an answer Im using BitmapSource.CopyPixels to extract the bytes from the BitmapSource… May 16, 2026 at 4:17 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I am using this code to write to a file in java. it has
A bug has been filed and fixed (super quickly) in SWT: https://bugs.eclipse.org/bugs/show_bug.cgi?id=305294 Just to
I have a source file in my project, which has more than 65,536 code
An interesting bug came up that I'm having no luck with. In a windowed
This code doesn't work: URL url = new URL( xmlPath ); InputSource input =
I've added this code below to a MOSS 2007 web part inside OnPreRender() method.
I'm getting a InvalidOperationException when trying to run this code: database.Produkts.SingleOrDefault<Produkt>(x => x.Kod ==
When my Tcpclient is working , with this code : TCPClient.Disconnect; TCPClient.Connect; I get
Possible Duplicate: or is not valid C++ : why does this code compile ?
I know the general guidelines to double-postbacks, but this one is driving me nuts

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.