Open System Services Porting Guide (G06.24+, H06.03+)
Table Of Contents
- What’s New in This Manual
- About This Manual
- 1 Introduction to Porting
- 2 The Development Environment
- 3 Useful Porting Tools
- 4 Interoperating Between User Environments
- Purpose of Interoperability
- The OSS User Environment
- OSS Commands for the Guardian User
- Guardian Commands for the UNIX User
- OSS Pathname and Guardian Filename Conversions
- Running the OSS Shell and Commands From TACL
- Running Guardian Commands From the OSS Shell
- Running OSS Processes With Guardian Attributes
- Using OSS Commands to Manage Guardian Objects
- 5 Interoperating Between Programming Environments
- 6 OSS Porting Considerations
- 7 Porting UNIX Applications to the OSS Environment
- 8 Migrating Guardian Applications to the OSS Environment
- General Migration Guidelines
- C Compiler Issues for Guardian Programs
- Using New and Extended Guardian Procedures
- Using OSS Functions in a Guardian Program
- Interoperating With OSS Programs
- Starting an OSS Program From the Guardian Environment
- C Compiler Considerations for OSS Programs
- Porting a Guardian Program to the OSS Environment
- How Arguments Are Passed to the C or C++ Program
- Differences in the Two Run-Time Environments
- Which Run-Time Routines Are Available
- Use of Common Run-Time Environment (CRE) Functions
- Replacing Guardian Procedure Calls With Equivalent OSS Functions
- Which IPC Mechanisms Can Be Used
- Interactions Between Guardian and OSS Functions
- 9 Porting From Specific UNIX Systems
- 10 Native Migration Overview
- 11 Porting or Migrating Sockets Applications
- 12 Porting Threaded Applications
- A Equivalent OSS and UNIX Commands for Guardian Users
- B Equivalent Guardian Commands for OSS and UNIX Users
- C Equivalent Inspect Debugging Commands for dbx Commands
- D Equivalent Native Inspect Debugging Commands for dbx Commands
- E Standard POSIX Threads Functions: Differences Between the Previous and Current Standards
- Glossary
- Index
Porting From Specific UNIX Systems
Open System Services Porting Guide—520573-006
9-9
Using Data Overlays
The endian problem affects programs that are ported between platforms that use
different byte-endian ordering when those programs access data within a word by
using byte addresses or bit locations. For example:
If var1=256+32+3, its value is 291 or 0x00000123.
If the value of var1 is manipulated as a unit, then no problem exists. However, if the
value is manipulated by byte, then the most significant byte of var1 contains 23 on a
little-endian system but contains 00 on a big-endian system. This difference is
important in the areas discussed in the following subsections:
•
Using Data Overlays on page 9-9
•
Initializing Multiple-Word Entities in Chunks of Multiple Bits on page 9-10
•
Using Bytes for More Than One Purpose on page 9-10
•
Using Hexadecimal Constants as Byte Arrays on page 9-10
In general, these practices are discouraged in modern C programs and should not be
used in source code that you need to port. However, you should check for them.
Using Data Overlays
Data overlays are possible in many programming languages:
•
In C, type unions, type casting, and unbounded arrays can all cause data overlay.
•
In COBOL, the use of REDEFINES causes data overlay.
•
In TAL, the use of address equations, empty arrays, and unbounded arrays can all
cause data overlay.
For example, unions such as the following can result in an endian problem:
union int_byte {
int_val;
char byte[4];
};
union int_byte my_var;
my_var.int_val = 0x1000000;
if(my_var.byte[3] == 0)
printf("The number is divisible by 256\n");
On a big-endian system, this code works correctly; byte 3 is the least significant byte
and contains 0 when my_var.int_val contains hexadecimal 1000000 and when that
number is divided by decimal 256. However, on a little-endian system, byte 3 is the
most significant byte and contains 1 initially when my_var.int_val contains
hexadecimal 1000000, even though hexadecimal 1000000 is evenly divisible by
decimal 256.
To fix this problem, use code such as the following that is not sensitive to endian
issues:
if((my_var.int_val & 0xff) == 0)
printf("The number is divisible by 256\n");