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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:13:16+00:00 2026-05-27T05:13:16+00:00

// assume file points to a file struct myStruct { WORD word; WORD word2;

  • 0
// assume file points to a file

struct myStruct
{
     WORD word;
     WORD word2;
};

Two competing codes: (1)

myStruct a;
a.word = 0xABCD;
a.word2 = 0xFADB;
fwrite(&a, sizeof(myStruct), 1, file);

output:
cdab dbfa

versus: (2)

DWORD word = 0xABCDFADB;
fwrite(&word, sizeof(DWORD), 1, file);

output:
dbfa cdab

My question is this: why isn’t fwrite amenable to writing the structure? I would assume that (1) would have equivalent output to (2). However, the fwrite is reading each struct member variable individually (and then writing them in little-endian order). Instead, I was expecting (1) to read the whole struct as one contiguous chunk, and start writing binary data starting at the end of this chunk (instead of at the end of the first member variable).

Thoughts?

  • 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-27T05:13:17+00:00Added an answer on May 27, 2026 at 5:13 am

    If you’re on a little-endian architecture, whole structs aren’t stored backwards; only the integers, pointers, and other numeric values are.

    Thus, when you have a struct containing two WORDs, each WORD is stored in little-endian order, but the fields themselves aren’t switched in memory. When you have a single DWORD, that’s a single unit, and it will be stored in little-endian.

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

Sidebar

Related Questions

Problem: I've a huge raw text file (assume of 3gig), I need to go
Assume you have a file which has been committed in your Git repo. You
Assume infile is a variable holding the name of an input file, and similarly
Lets assume my classes are loaded from a compressed .war file or loaded elsewhere,
Let's assume I have a main script, main.py, that imports another python file with
What is the best way to handle browser-specific CSS file loading? Assume you are
Assume that I have some HTML page, and a corresponding CSS file. I'd like
I'm writing information to a file, through a DataOutputStream (RandomAccessFile->FileOutputStream->BufferedOutputStream->DataOutputStream). I assume that if
Is it possible to configure the default file extension that Oracle's Pro*COBOL precompiler assumes
Assume java 1.6 and leopard. Ideally, it would also be nice to get a

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.