delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/07/02/06:40:27

From: "Javier Calleja" <dismuntel AT apdo DOT com>
To: "djgpp" <djgpp AT delorie DOT com>
Subject: Size of a struct is not correct
Date: Thu, 2 Jul 1998 12:40:18 +0200
Message-ID: <01bda5a5$ce48b420$0100a8c0@dismuntel.ctv.es>
MIME-Version: 1.0

Hi world

  I have built the following struct:

  struct
  {
    char one;
    short two,three;
    long  four
  } foo;

    But when I do sizeof of this struct, the result is wrong (it says the
struct has 12 bytes).
    I think gcc tryes to allocate the struct variables in blocks of 4 bytes.
    But I have a problem, because I use the following sentence:

    memcpy(pointer_to_memory,&foo,sizeof(foo));

   And I must to allocate each variable in a memory position of 9 bytes,
when the first byte is one variable, the following two bytes are a short
variable, ...

  Does anything have a solution?

  Thanks


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019