Thread: C Structure Padding

  1. #16
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    It would make more sense that it aligned the odd chars on a DWORD boundary, though. At least to me.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #17
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by Elysia View Post
    It would make more sense that it aligned the odd chars on a DWORD boundary, though. At least to me.
    Wild guessing: Presumably this is so, if someone like cus comes along who wants to copy one struct into another struct, and the struct that person is copying has just the two char arrays in it (and not everything else), then the alignments still match. After all, chars don't align on a DWORD.

  3. #18
    Registered User
    Join Date
    Apr 2008
    Posts
    396
    Nope, it's definitely (at least on this machine) 7+7+2+4.
    Yes this is possible, bytes and byte arrays are aligned by definition, so no padding is required here, only objects greater than 1 byte (and accessed as such) have to be aligned.

  4. #19
    Registered User
    Join Date
    Jul 2011
    Posts
    2
    Structure Padding is done to do memory alignment. As size of pointer is 4 bytes, if everything is organized by multiple of 4, that it will be easier and faster to calculate the address and processing them. Structure padding in C

  5. #20
    Registered User
    Join Date
    May 2011
    Location
    Around 8.3 light-minutes from the Sun
    Posts
    1,949
    Ok, we get it. Welcome to the forum. Now please stop bumping old threads with what you just learned today. (Based on ALL the other threads bumped).
    Quote Originally Posted by anduril462 View Post
    Now, please, for the love of all things good and holy, think about what you're doing! Don't just run around willy-nilly, coding like a drunk two-year-old....
    Quote Originally Posted by quzah View Post
    ..... Just don't be surprised when I say you aren't using standard C anymore, and as such,are off in your own little universe that I will completely disregard.
    Warning: Some or all of my posted code may be non-standard and as such should not be used and in no case looked at.

  6. #21
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    I have deleted the other zombie posts.

    *thread closed*
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to handle structure padding
    By cdalten in forum C Programming
    Replies: 8
    Last Post: 03-17-2006, 09:29 PM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. Structure Padding, pragma pack...
    By P.Phant in forum C Programming
    Replies: 4
    Last Post: 06-04-2003, 05:56 AM
  4. Detecting Structure Padding
    By johnnie2 in forum C++ Programming
    Replies: 2
    Last Post: 03-17-2003, 10:25 AM
  5. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 10:52 AM