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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:31:01+00:00 2026-05-22T11:31:01+00:00

A stream of chars are sent out to a communication device. For readability purposes,

  • 0

A stream of chars are sent out to a communication device. For readability purposes, i wrote inidividual configurations as variables:

unsigned char a1;
unsigned char a2;
unsigned char a3;
unsigned char a4;
unsigned char a5;
std::string a6;
unsigned char a7;
unsigned char a8;

What is the best way to pack it into a variable tightly so that it’s aligned perfectly?
Till now I’ve think of put everything into a struct.

edit: struct doesn’t look like a viable option since struct doesn’t hold string, and string is varying in size, although is a one time declared thing. Compiled in GCC

edit2: Gonna go with packed struct method, but will convert the string to a c_str first. Until a better answer, this is the way to be.

  • 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-22T11:31:02+00:00Added an answer on May 22, 2026 at 11:31 am

    A packed structure, rather than just a structure would be more appropriate.

    EDIT: Ofcourse, you should not use string as a part of your structure, It skipped me while answering but as others have pointed out. You should conver string to character array using str.c_str()); and then store the same in the packed structure.

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

Sidebar

Related Questions

I'm reading data from a stream into a char array of a given length,
I have an char* array of binary data. It is binary media-stream encoded with
I've got raw data streams from image files, like: vector<char> rawData(fileSize); ifstream inFile(image.jpg); inFile.read(&rawData[0]);
This is the data stream, (Hope I'm displaying this correctly, it took me forever
I created a feature stream yesterday. Mainstream(US Mastership) | |----FeatureStream(US Mastership) | |---FeatureStreamIndia(India Mastership)
Is it possible to stream an FTP upload with PHP? I have files I
I have a stream of JSON coming back and am building a table dynamically
I am receiving a stream of unordered Int32 values and need to track the
I record Live Stream With Red5 Media Server successfully. But the recorded video saved
I'm trying implement server code of Server-Sent Events in a generic way that any

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.