- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Long word (4 byte boundry) requirement in C for st...
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-03-2002 02:34 PM
тАО04-03-2002 02:34 PM
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-03-2002 03:09 PM
тАО04-03-2002 03:09 PM
Re: Long word (4 byte boundry) requirement in C for structures
#pragma HP_ALIGN HPUX_WORD
Results in int and float types being halfword aligned (two-byte aligned), doubles being word aligned (four byte aligned), and all structs being
at least halfword aligned. This is the default for the Series 300/400 computer.
#pragma HP_ALIGN HPUX_NATURAL_S500
Results in doubles being word aligned. This is the default for the Series 500 computer.
#pragma HP_ALIGN HPUX_NATURAL
Results in native alignment for the HP 9000 workstations and servers. The int and float types are word aligned, doubles are double-word
aligned (8-byte aligned), and structs may be byte aligned depending upon the data types used within the structure.
#pragma HP_ALIGN NATURAL
Results in a superset of the above. Uses native alignment provided by HPUX_NATURAL, all structs and unions are at least halfword aligned, and
DOMAIN bit-field mapping is used. (See Chapter 2, "Storage and Alignment Comparisons," in the HP C/HP-UX Programmer's Guide for details
regarding Domain bit-fields.)
#pragma HP_ALIGN DOMAIN_NATURAL
Similar to NATURAL except long doubles are only 8 bytes long (treated as doubles).
#pragma HP_ALIGN DOMAIN_WORD
Similar to HPUX_WORD, with the following exceptions: long doubles are only 8 bytes long (treated as doubles) and DOMAIN bit-field mapping is
used. Refer to Chapter 2, "Storage and Alignment Comparisons," in the HP C/HP-UX Programmer's Guide for detailed information on Domain
bit-fields.
#pragma HP_ALIGN NOPADDING
Causes all structure and union members that are not bit-fields to be packed on a byte boundary. It does not cause crunched data packing, where
there are zero bits of padding. It only ensures that there will be no full bytes of padding in the structure or union.
Accessing Data with the HP_ALIGN Pragma
The HP_ALIGN pragma isolates data structures that are not naturally aligned for PA-RISC systems.
References to non-natively aligned data often results in poorer run-time performance than references to natively aligned data. Natively aligned data is
often accessed with a single load or store instruction. Non-natively aligned data must be accessed with one or more load and store instructions.
in addition, if you only need this for a limited section of code you can do something like this:
#pragma HP_ALIGN HPUX_WORD PUSH
This sets the alignment to HPUX_WORD and pushes the current setting onto a stack for later retrievel via
#pragma HP_ALIGN POP
All of this is available in your Online Help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-03-2002 09:39 PM
тАО04-03-2002 09:39 PM
Re: Long word (4 byte boundry) requirement in C for structures
Most of the compilers allow to change this default alignment and padding (adding spaces between members of a struct). But generally this will result in longer code and execution time.
See Clays posting how to change aligment using HPs native compilers.
For the GNU compiler see "Specifying Attributes of Variables"
http://gcc.gnu.org/onlinedocs/gcc-3.0.4/gcc_5.html#SEC101
Hardy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-04-2002 10:51 AM
тАО04-04-2002 10:51 AM
Solutionthe man page:
+unum
Allow pointers to access non-natively aligned
data. This option alters the way that the
compiler accesses dereferenced data. Use of
this option may reduce the efficiency of
generated code.
...
However, this sort of thing is always tricky. You
really would be better off using XDR, or using
your own byte-level manipulations (assuming you
know the memory layout of the original data).
Good luck!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-04-2002 12:15 PM
тАО04-04-2002 12:15 PM
Re: Long word (4 byte boundry) requirement in C for structures
void func(arg1,arg2)
int arg1;
int arg2;
Yet new programs that use them
may declare them:
void func(int arg1,int arg2);
With the pragma statement (any of them) this became an error and things would not compil:
error 1584: Inconsistent type declaration: func
Without the pragma these compil and work properly. The application is 181224 files in who knows how many directories and all with sccs. I was unwilling to go "fix" all these. I tried many different ANSI switches to no avail.
The suggestion to use the compiler switch "-n1" however worked perfectly and does not have this weird declaration problem and my application at first blush is working properly. It will take weeks to actually test it completely and I will have other questions!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-05-2002 06:11 AM
тАО04-05-2002 06:11 AM
Re: Long word (4 byte boundry) requirement in C for structures
K&R have documented the problem you ar running into with structures. sizeof(struct) is allowed to be different than the sum of sizeof(field) making up the structure, and offset of a field is not necessarily the sum of the sizes of the preceding fields making up the structure. If memory is not an issue, there should be a pragma to let the compiler align stucture fields on machine boundaries. This can be a harware performance issue.
If you can restructure your structures, try placing the fields in order by size with largest fields first. This will make the structures much more portable and efficient.