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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:17:35+00:00 2026-06-09T09:17:35+00:00

http://c-faq.com/strangeprob/ptralign.html In 16.7, the author explains: s.i32 = *(long int *)p; s.i16 = *(int

  • 0

http://c-faq.com/strangeprob/ptralign.html

In 16.7, the author explains:

s.i32 = *(long int *)p;
s.i16 = *(int *)p;

will get into trouble ’cause these casted pointer may not be aligned. So he uses byte wise manipulation instead for solution.

My question is, since this code:

struct mystruct {
    char c;
    long int i32;
    int i16;
} s;

will have padding bytes after char c;, why didn’t the author skip the padding when he try to get the long int i32;?

  • 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-09T09:17:36+00:00Added an answer on June 9, 2026 at 9:17 am

    Keep in mind this is supposed to be a FAQ list. You have to read the Q and the A as if they were written by different people. Theoretically, the Q is something that actually gets Asked Frequently by people who don’t know the answer. In reality it’s probably not a direct quote from an actual question, but a sort of idealized version of the question made up by the FAQ list maintainter. But still, when writing the Q section the author adopts a different persona.

    In this case the questioning persona doesn’t know about alignment or padding. He writes char buf[7] and the struct definition and thinks they should both be 7 bytes long. The 7-byte buffer is an external data format (in a file or a network protocol stream) that the questioner is trying to parse, the struct represents the variables he would like to parse it into, and the statements like s.i32 = *(long int *)p; are his unsuccessful attempt at doing it.

    In the A section, our author drops that persona and gives the correct method of transferring the data from the packed 7-byte buffer into the struct. He doesn’t explain every detail of alignment and padding rules as applied to the struct and the char buffer because he wants to keep the answer brief.

    You’re looking at a true old-style newsgroup FAQ list, which was designed to actually answer the questions that people ask frequently, not a corporate web-site style “FAQ” in which a marketing team makes up fake questions designed to flatter the company and avoid answering any complaints. (And does anybody else remember when there was a distinction between a FAQ which was a single question and a FAQL which was the FAQ List with answers? Where did that go?)

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

Sidebar

Related Questions

What delay-load dependencies\functions are meant for in the following document? http://www.dependencywalker.com/faq.html Thanks
I've read through the FAQ of Android Dev Guid (http://developer.android.com/guide/appendix/faq/commontasks.html#opennewscreen ) but I'm not
In http://www.parashift.com/c++-faq-lite/intrinsic-types.html#faq-26.6 , it is wriiten that Another valid approach would be to define
I found (in http://c-faq.com/ansi/avail.html ) that An electronic (PDF) copy is available on-line, for
I know destructor shouldn't not throw exception. http://www.parashift.com/c++-faq-lite/dtors.html#faq-11.13 I have the following code :
// http://www.parashift.com/c++-faq-lite/misc-technical-issues.html class BadConversion : public std::runtime_error { public: BadConversion(std::string const& s) : std::runtime_error(s)
According to Java Generics FAQ http://www.angelikalanger.com/GenericsFAQ/FAQSections/TypeParameters.html#FAQ302 a type parameter cannot be forward-referenced in this
From http://www.jibbering.com/faq/faq_notes/closures.html : Note: ECMAScript defines an internal [[prototype]] property of the internal Object
From c++ FAQ: http://www.parashift.com/c++-faq-lite/dtors.html#faq-11.9 Remember: delete p does two things: it calls the destructor
From http://www.parashift.com/c++-faq-lite/basics-of-inheritance.html#faq-19.5 A member (either data member or member function) declared in a protected

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.