Padding issues between Sparc and Intel


 
Thread Tools Search this Thread
Top Forums Programming Padding issues between Sparc and Intel
# 1  
Old 07-31-2011
Padding issues between Sparc and Intel

Hello,
I'm facing severe structure padding issues when my Solaris C/C++ application that runs on Sparc communicates with the same C/C++ application that runs on 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. The structure that is exhanged between the two machines contains both uint32_t and uint64_t variables.
I could add some extra uint32_t 0s in the structure definition in case of Intel but this is not an actual clean solution.

Is there a way to resolve this padding issue?

Thanx in advance.
# 2  
Old 07-31-2011
You should post your question here , it will attract more attention
also you can have look here , here and here

Last edited by h@foorsa.biz; 07-31-2011 at 02:25 PM..
This User Gave Thanks to h@foorsa.biz For This Post:
# 3  
Old 07-31-2011
Aside from alignment issues, you may also have to consider endianness. Intel x86 is little endian and Sparc may be big endian (some are purely big endian and some are bi).

Regards,
Alister
# 4  
Old 08-01-2011
Padding issues between Sparc and Intel

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.

Moderator's Comments:
Mod Comment Moved into previous post

Last edited by pludi; 08-01-2011 at 04:10 AM..
# 5  
Old 08-01-2011
First, always put the largest elements of your structure first.

Second, what compiler are you using? What compiler options?

Third, have you even looked into the endian differences between SPARC and x86?
# 6  
Old 08-01-2011
You cannot safely pass structures/unions/etc between disparate computing platforms in the way that you seem to expect it to work. Aside from endianness issues, there are structure packing and alignment issues, programming model issues, etc.

This problem has been solved a long time ago. Check out IDL - Interface Description Language, RPC, CORBA, etc.
# 7  
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..
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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
Login or Register to Ask a Question