Message-ID: <359B7F4B.2AB85208@ipass.net> From: Terry MIME-Version: 1.0 Newsgroups: comp.os.msdos.djgpp Subject: Re: Size of a struct is not correct References: <01bda5a5$ce48b420$0100a8c0 AT dismuntel DOT ctv DOT es> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 28 Date: Thu, 02 Jul 1998 12:44:02 GMT NNTP-Posting-Host: ts3-166-ppp.ipass.net NNTP-Posting-Date: Thu, 02 Jul 1998 08:44:02 EDT Organization: iPass.Net To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Precedence: bulk Javier Calleja wrote: > > 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, ... By default, all variables are aligned on four byte boundaries. There is an option to change that to a byte boundary. Terry