Sponsored Content
Top Forums Programming Padding issues between Sparc and Intel Post 302543593 by alister on Monday 1st of August 2011 10:22:27 AM
Old 08-01-2011
Quote:
Originally Posted by Goseib
Hello,
I'm facing structure padding issues when my Solaris 32-bit C/C++ application that runs on Sparc communicates with the same C/C++ application that runs on 32-bit Intel. I know that Sparc and Intel use different padding patterns. So when it comes to reading the exchanged structure data, both machines read the wrong data.

My structure is of the form:
Code:
typedef struct {
  uint8_t a;
  uint8_t b;
  uint16_t c;
  uint32_t d;
  uint64_t e;
  struct {
      uint64_t f;
      uint32_t g;
  } inner_struct;
  uint32_t h;
  uint32_t i;
  uint16_t j;
  uint16_t k;
  uint64_t l;
} outter_struct;

Is there a way to resolve this padding issue?

Thanx in advance.
Quote:
Originally Posted by Goseib
Is there a way to resolve this padding issue?
The padding issue is simple to avoid. Simply do not write/read structs. Instead, write/read each member, recursively when a nested struct is encountered.

Since you're using fixed-width numeric types, implementation-defined size variance is not an issue.

However, you still have to worry about endianness if you're reading/writing multibyte types across different hardware platforms (even when they're running the same operating system). In this case, all members of your struct are simple numeric types (flattening the nested struct), so you may be able to write/read them using the standard ntoh*/hton* libc functions if the c libraries of all relevant platforms provide a 64-bit extension. If no 64-bit version of those functions is available, you could play games with casting, pointers, bitmasks, bitshifting, etc ... to massage the 64-bit types into network byte order. Or, perhaps you could avoid all of the above and use an implementation of XDR (or something similar).

In case you you haven't used them, the keywords 'serialization' and 'marshalling' should be helpful in searching/googling for further information on this topic.

Regards,
Alister

Last edited by alister; 08-01-2011 at 11:51 AM..
 

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Sparc vs Intel performance

Hello all, I have been trying to find any data that states what platform would garner better overall performance in an Oracle Cluster. The scenario: This is a high traffic e-commerce site with IIS and Commerce server on the front end. The backend consists of a Sun Solaris hardware/software... (7 Replies)
Discussion started by: kmgrady01
7 Replies

2. UNIX for Advanced & Expert Users

Padding issues

Hello, Structure padding & structure size are different on Compaq & HP UNIX. When structures are transfered via netfork from Compaq to HP will this be a problem? If yes, what can be the solution? Thanks, shilpa (2 Replies)
Discussion started by: informshilpa
2 Replies

3. UNIX for Dummies Questions & Answers

Padding

Hi Can anyone tell me how to pad zeroes on the left side to a numeric string in unix shell scripting Your answer is very much appreciated Thanks Vijay (2 Replies)
Discussion started by: vijaygopalsk
2 Replies

4. UNIX for Dummies Questions & Answers

Zero padding dates

I have a file with records containing dates like: SMPBR|DUP-DO NOT USE|NEW YORK||16105|BA5270715|2007-6-6|MWERNER|109||||JOHN||SMITH|MD|72211118||||||74559|21 WILMINGTON RD||D|2003-11-6|SL# MD CONTACT-LIZ RICHARDS|||0|Y|N||1411458| How can I get the date fields in each of my records to be... (1 Reply)
Discussion started by: ChicagoBlues
1 Replies

5. Shell Programming and Scripting

fixed length text file padding issues in AIX

Hi, I have a fixed length text file that needs to be cut into individual files in aix and facing padding issues. If I have multiple blank spaces in the file it is just making it one while cutting the files.. Eg:- $ - blank space filename:file.txt ... (2 Replies)
Discussion started by: techmoris
2 Replies

6. UNIX for Dummies Questions & Answers

can I emulate solaris/sparc on virtualbox? Or other emulator to run solaris for sparc in my win7 PC?

Hi Gurus can I emulate solaris/sparc on virtualbox? Or other emulator to run solaris for sparc in my win7 PC? regards, Israel. (9 Replies)
Discussion started by: iga3725
9 Replies

7. Ubuntu

Sudo issues with Ubuntu 7.10 Running on a Ultra SPARC Machine

I have a Sun Blade 1000 machine that I installed Ubuntu 7.10 SPARC onto. The only user configured (configure during install) cannot use sudo. When I try to issue a command using sudo (ex. sudo apt-get install) it asks me for my password and returns the error "user not found in sudoers file". I need... (4 Replies)
Discussion started by: swilso
4 Replies

8. Solaris

Running Solaris SPARC on Intel Hardware????

Hello friends, I hope everyone is fine and doing well. I want to learn Assembly language for SPARC architecture. Is there any emulator available for 64 bit SPARC on which one can install Oracle Solaris 11 SPARC version. And ofcourse on my intel laptop computer??? Thanks! (4 Replies)
Discussion started by: gabam
4 Replies
All times are GMT -4. The time now is 01:22 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy