Re: porting solaris/SPARC app to Solaris/x86 questions

From: Shea Martin (smartin_at_arcis.com)
Date: 12/13/04


Date: Mon, 13 Dec 2004 15:55:42 -0700

Jens.Toerring@physik.fu-berlin.de wrote:
> Shea Martin <smartin@arcis.com> wrote:
>
>> As you have guessed, there are 5+
>>years of files written out in "carefree mode". Adapting code
>>specifically for the x86 version is the route we will have to go. How
>>do I know how a struct is padded etc? Do i have to reverse engineer it;
>>frwrite a struct, then hex-dump the file to see how it is actually padded?
>
>
> The simplest way is probably writing a short program where you define
> a structure like the one in the real program and than calculate the
> offsets of the members, e.g. something like
>
> struct s_t {
> int x;
> int y;
> float z;
> float a;
> int b;
> u_longlong_t address;
> } s;
>
> printf( "total length of structure: %lu\n", ( unsigned long ) sizeof s );
> printf( "offset of y: %lu\n", ( unsigned long ) offsetof( struct s_t, y ) );
> printf( "offset of z: %lu\n", ( unsigned long ) offsetof( struct s_t, z ) );
>
> You can then use the offsets on the new machine in order to extract
> the fields from the raw data you have read into a buffer (you don't
> need that for the first element since it is guaranteed to be exactly
> at the start of the structure). What I would be worried about a bit
> more is if the representation of floats on both architectures is
> the same. And I hope you're not really storing addresses in the
> structure as the name of the last member might indicate...
>
> Regards, Jens
Thanks,

I was unfamiliar with the offsetof macro. This looks exactly like what
I must do.

As for the address, you are correct, it is storing an fseek number, the
header acts as an index for the LARGE binary file. But it is only
needed when randomly accessing the file, it is not used for sequential
access, so we should be alright.

Thanks,

~S



Relevant Pages

  • Re: Reading a Binary File....
    ... I have a problem in reading a binary file. ... int acountnum; ... float value; ... char phone; ...
    (comp.lang.c)
  • Re: Abnormal program termination
    ... foo.c:4: warning: function declaration isn't a prototype ... Your version is legal under C90 rules, but int mainis more explicit ... float ave(), average; ...
    (comp.lang.c)
  • RTF Render with Scale
    ... float fHorzSizeInches = nHorzSize / 25.4f; ... IntPtr hdc = graphics.GetHdc; ... int nHorzSize = SafeNativeMethods.GetDeviceCaps(hdc, ... PHYSICALWIDTH = 110, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: RAD vs. performance
    ... work with both int and float. ... name (e.g. "+" for both int and float addition). ... Again, it's a compatibility issue. ... contend that assuming interfaces are equivalent and inferring the most ...
    (comp.lang.misc)
  • (part1b) Han from China teaches you C
    ... int flist, mlist, slist; ... float board_size; ... static void draw_tube(float bottom_radius, float top_radius, ... glVertex3f(xmin, ymin, zmax); glVertex3f; ...
    (comp.lang.c)