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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:03:54+00:00 2026-06-10T15:03:54+00:00

Can I populate a struct by treating it as an array of unsigned char

  • 0

Can I populate a struct by treating it as an array of unsigned char values?

I receive character data over the RS232 UART from a Microcontroller. Using C, how can I deserialize the char Array in my Datatypes uint16_t, uin32_t, int32_t[], …

e.g.

uin16_t StartID = ARRAY[0];
uin16_t EndID = ARRAY[246];

… is there something like this ?
In C# there are effective functions for deserialization but im not that in C

for later

if (StartID == 11)
    printf("good"); 
else 
    printf("bad");

I made this struct to work easier later with the Data. Is there a way to get the Data from my ARRAY[248] into my struct?

typedef struct
{
  //Header 6byte
  uint16_t StartID; // Check if its 1 or in hex 0b
  uint16_t ID;      
  uint16_t LoadID;  

  //Payload 240 byte
  int32_t POS01[3];  
  int32_t POS02[3];
  int32_t POS03[3];
  int32_t POS04[3];
  int32_t POS05[3];
  int32_t POS06[3];
  int32_t POS07[3];
  int32_t POS08[3];
  int32_t POS09[3];
  int32_t POS10[3];
  int32_t POS11[3];
  int32_t POS12[3];
  int32_t POS13[3];
  int32_t POS14[3];
  int32_t POS15[3];
  int32_t POS16[3];
  int32_t POS17[3];
  int32_t POS18[3];
  int32_t POS19[3];
  int32_t POS20[3];

  //End 2byte
  uint16_t EndID; // Check if its 47 or in hex 2F

} DATA_POS; //TOTAL = 248byte
  • 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-10T15:03:56+00:00Added an answer on June 10, 2026 at 3:03 pm

    C has a feature called pointers:

    uin16_t *StartID = (void*)&ARRAY[0];
    uin16_t *EndID = (void*)&ARRAY[246];
    

    Other means to access data under another format include unions:

       union 
       {
          uint32_t *u32;
          uint16_t *u16;
          uint8_t  *u8;
       } u;
    

    As you can see, sometimes features do not need a dedicated function.

    Beware however that alignment issues could arise on some platforms because of accessing data in such a way.

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

Sidebar

Related Questions

Can you populate a set from a soql query? I couldn't get my syntax
How can i populate an array in loop? I'd like to do something like
How can I do this in Javascript/jQuery from PHP? I am trying to populate
I wanted to see if you can populate a range all at once from
I have the following struct defining data returned from a collection of HID device
How can I populate multiple datagrids in flex with a single datasource that is
How can I get the variable My.Application.Info.Version.ToString to populate in the comments section? Dim
I have a requirement where I can use JS Fiddle dropdown to populate States
Can someone point me to an article that shows the dropdownlist being populated from
How to define a struct whose members can be accessed by any internal classes

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.