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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:09:34+00:00 2026-05-29T06:09:34+00:00

From http://www.doc.ic.ac.uk/teaching/projects/Distinguished03/AndrewSuffield.pdf : #include <string.h> struct x { char s[10]; int a[4]; }; void

  • 0

From http://www.doc.ic.ac.uk/teaching/projects/Distinguished03/AndrewSuffield.pdf:

#include <string.h>

struct x
{
  char s[10];
  int a[4];
};

void bang(struct x *d)
{
  strcat(d->s, "!");
}

int main(void)
{
  struct x d;
  strcpy(d.s, "012345678");
  d.a[0] = 3;
  d.a[1] = 2;
  d.a[2] = 1;
  d.a[3] = 0;
  bang(&d);
  return a[0];
}

In this example, struct x contains a 10-byte string immediately followed by a 4-integer array. d is initialized with a 9-character string (occupying 10 bytes because of the trailing NULL) and four integers. bang() appends a ! to the string, making it “012345678!” plus a trailing NULL.

The NULL byte at the end of the string will overwrite the first byte of d.a[0]. On a
big-endian host, this will have no effect because that byte was already zero. On a little-endian host, this will change the value of d.a[0] to zero

Two questions:

  1. Will there not be structure holes present between s & a and so the above argument does not hold. gcc gives return vaue as 3.
  2. return a[0] does not work on my system (gcc).
  • 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-29T06:09:35+00:00Added an answer on May 29, 2026 at 6:09 am
    1. There could very well be padding between the fields. On any modern system there will be. Try passing strcat a longer string.
    2. return a[0] is clearly a typo. It should read return d.a[0].
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is an example of polymorphism from http://www.cplusplus.com/doc/tutorial/polymorphism.html (edited for readability): // abstract base
I was just reading a little bit on them from http://www.cplusplus.com/doc/tutorial/namespaces/ and it seems
I'am trying to understand the example from program_options of the boost library ( http://www.boost.org/doc/libs/1_38_0/doc/html/program_options/tutorial.html#id3761458
Taken from here: http://www.cplusplus.com/doc/tutorial/inheritance/ What is inherited from the base class? In principle, a
The example I'm trying to compile is from: http://www.boost.org/doc/libs/1_46_1/doc/html/boost_asio/examples.html (the chat example) Here is
I'm trying to compile the NIF Test from Erlang ( http://www.erlang.org/doc/man/erl_nif.html ) on Mac
From http://www.jibbering.com/faq/faq_notes/closures.html : Note: ECMAScript defines an internal [[prototype]] property of the internal Object
From http://www.faqs.org/rfcs/rfc2822.html : CR and LF MUST only occur together as CRLF; they MUST
this is copied from http://www.zenspider.com/ZSS/Products/RubyInline/Readme.html , the home of rubyinline, adding/moding as indicated in
I used the code from http://www.rgagnon.com/javadetails/java-0580.html to get Motherboard Id, but the result is

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.