public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* sizeof and alignement
@ 2000-03-29 23:20 David Martinez Garcia
  2000-03-30  6:45 ` Martin v. Loewis
  2000-04-01  0:00 ` David Martinez Garcia
  0 siblings, 2 replies; 4+ messages in thread
From: David Martinez Garcia @ 2000-03-29 23:20 UTC (permalink / raw)
  To: help-gcc

Dear friends,
We have compiled (using gcc on Linux-Intel platform) with succes some
applications developed in Solaris. Now we want to read the information of
binary files produced in the Sun platform but we have a problem. In
several cases the command 'sizeof' gives different values in both
platforms. Generally only few bytes (4, 8, 12...). We think this is due to
the memory alignment that is forced in the Sun platform. This differences
avoid us to read the right number of bytes when some complex structures
have been writen using the sizeof command in the fwrite instructions.  Is
there any way for solving this problem ? Can we force the gcc compiler to
modify the alignment of the produced code ? Where can we find information
about this common problems when porting applications ?

If you are able of answer any of the previous questions it would be great.
--
David Martinez Garcia
david@fssintl.com
FSS International Europe
Tel. +34 963 826 394
Fax  +34 963 826 392

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: sizeof and alignement
  2000-03-29 23:20 sizeof and alignement David Martinez Garcia
@ 2000-03-30  6:45 ` Martin v. Loewis
  2000-04-01  0:00   ` Martin v. Loewis
  2000-04-01  0:00 ` David Martinez Garcia
  1 sibling, 1 reply; 4+ messages in thread
From: Martin v. Loewis @ 2000-03-30  6:45 UTC (permalink / raw)
  To: david; +Cc: help-gcc

> Generally only few bytes (4, 8, 12...). We think this is due to the
> memory alignment that is forced in the Sun platform. ... Is there
> any way for solving this problem ?

It's hard to tell whether there is a solution, without seeing the
specific structures in question. For example, your analysis that
memory alignment is the cause could be incorrect, in which case
proposals for solutions would be on the wrong track.

> Can we force the gcc compiler to modify the alignment of the
> produced code ?

To a limited degree, yes; there is a specific __attribute__
declaration for that. Please have a look in the GCC manual, (gcc)Type
Attributes.

> Where can we find information about this common problems when
> porting applications ?

The problem is not as common as you think. Because of the problems,
many people avoid exchanging ad-hoc binary data.

Even if you get sizes and alignment right, you still have to fight
endianness: Sparc is big-endian, Intel little-endian. That means all
the values will be incorrect.

Regards,
Martin

^ permalink raw reply	[flat|nested] 4+ messages in thread

* sizeof and alignement
  2000-03-29 23:20 sizeof and alignement David Martinez Garcia
  2000-03-30  6:45 ` Martin v. Loewis
@ 2000-04-01  0:00 ` David Martinez Garcia
  1 sibling, 0 replies; 4+ messages in thread
From: David Martinez Garcia @ 2000-04-01  0:00 UTC (permalink / raw)
  To: help-gcc

Dear friends,
We have compiled (using gcc on Linux-Intel platform) with succes some
applications developed in Solaris. Now we want to read the information of
binary files produced in the Sun platform but we have a problem. In
several cases the command 'sizeof' gives different values in both
platforms. Generally only few bytes (4, 8, 12...). We think this is due to
the memory alignment that is forced in the Sun platform. This differences
avoid us to read the right number of bytes when some complex structures
have been writen using the sizeof command in the fwrite instructions.  Is
there any way for solving this problem ? Can we force the gcc compiler to
modify the alignment of the produced code ? Where can we find information
about this common problems when porting applications ?

If you are able of answer any of the previous questions it would be great.
--
David Martinez Garcia
david@fssintl.com
FSS International Europe
Tel. +34 963 826 394
Fax  +34 963 826 392

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: sizeof and alignement
  2000-03-30  6:45 ` Martin v. Loewis
@ 2000-04-01  0:00   ` Martin v. Loewis
  0 siblings, 0 replies; 4+ messages in thread
From: Martin v. Loewis @ 2000-04-01  0:00 UTC (permalink / raw)
  To: david; +Cc: help-gcc

> Generally only few bytes (4, 8, 12...). We think this is due to the
> memory alignment that is forced in the Sun platform. ... Is there
> any way for solving this problem ?

It's hard to tell whether there is a solution, without seeing the
specific structures in question. For example, your analysis that
memory alignment is the cause could be incorrect, in which case
proposals for solutions would be on the wrong track.

> Can we force the gcc compiler to modify the alignment of the
> produced code ?

To a limited degree, yes; there is a specific __attribute__
declaration for that. Please have a look in the GCC manual, (gcc)Type
Attributes.

> Where can we find information about this common problems when
> porting applications ?

The problem is not as common as you think. Because of the problems,
many people avoid exchanging ad-hoc binary data.

Even if you get sizes and alignment right, you still have to fight
endianness: Sparc is big-endian, Intel little-endian. That means all
the values will be incorrect.

Regards,
Martin

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2000-04-01  0:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-03-29 23:20 sizeof and alignement David Martinez Garcia
2000-03-30  6:45 ` Martin v. Loewis
2000-04-01  0:00   ` Martin v. Loewis
2000-04-01  0:00 ` David Martinez Garcia

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).