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

  • Home
  • SEARCH
  • 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 8711563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:54:30+00:00 2026-06-13T04:54:30+00:00

I have two arrays. And I am calling a function inside main in which

  • 0

I have two arrays. And I am calling a function inside main in which I am updating one of the arrays according to some of the values in the other array.

volatile float32_t raw_data[3]; //this is being updated by an interrupt handler
void get_acc(int32_t* acc_data, float32_t* raw_data)
{
  acc_data[0] = (raw_data[0] - OFFSETX)/SENSX; //OFFSETX and SENSX defined as a macro
  acc_data[1] = (raw_data[1] - OFFSETY)/SENSY;
  acc_data[2] = (raw_data[2] - OFFSETZ)/SENSZ;
}
int main()
{
  int32_t acc_data[3];      
  int32_t data_ready = 0;  //being updated by interrupt handler
  while(1)
  {
  if(data_ready)
  get_acc(acc_data,raw_data);
  }
}

To my absolute shock, when I watch the variables using breakpoints and stepping through get_acc, only the first one acc_data[0] gets updated, all others are set to 0 even though they are executed. Now my first suspicion is it is something related to pointer, probably the address not being updated properly. Because I have used passing arrays to function like that where I updated the array indexes inside a for loop, not manually.
Can anybody give an insight what might be wrong.

  • 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-13T04:54:31+00:00Added an answer on June 13, 2026 at 4:54 am

    You probably have subtle synchronization errors here:

    1. As Jonathan pointed out raw_data has lost its qualifier inside the function. Using a volatile variable in such a way is undefined behavior, even if there is no signal handler involved.
    2. It seems in addition that your data is touched asynchronously by a signal handler. The only data type as of C99 that you may touch with such a signal handler is sig_atomic_t. C11 goes a bit further and also allows for other lock free atomic types:

    When the processing of the abstract machine is interrupted by receipt
    of a signal, the values of objects that are neither lock-free atomic
    objects nor of type volatile sig_atomic_t are unspecified, as is the
    state of the floating-point environment. The value of any object
    modified by the handler that is neither a lock-free atomic object nor
    of
    type volatile sig_atomic_t becomes indeterminate when the handler exits, as does the state of the floating-point environment if it is
    modified by the handler and not
    restored to its original state.

    As you see, especially touching floating points is considered a no go.

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

Sidebar

Related Questions

I have two arrays, one is very large (more than million entries) and other
I have two arrays with time values in them in this format. 00:00:00 which
I have two arrays. I'd like to copy ranges of data from one of
I have two arrays and I post the arrays in one input; <input name='sistem[]'
I have two arrays, the first one contents numbers and the second one use
I have two arrays... $Name = array(a, b, c, d); $Value = array(1, 2,
I have two arrays in php that contain custom class objects. One I iterate
I have a function in PostgreSQL (PLPGSQL) that returns an array containing two elements.
I am calling a function twice from two different functions, But for one of
I have two questions: First: I have a function which returns a HashMap. To

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.