Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.

Byte alignment on IA-32

goelvineet
Beginner
587 Views

Hi,

I am working on application running on HPopenVMS/Itanium (IA-32).

I got doubt that if the compiler padded some bytes to make structure align on byte boundry, does that padded data is initialized? Does compiler padded garbage data into structure under the hood?

Can some one through some light on Alignment of stack variable vs Alignment of globacl or static variable.

TIA

Vineet.

0 Kudos
5 Replies
JenniferJ
Moderator
587 Views
"Itanium (IA-32)", do you mean IA-64?
0 Kudos
goelvineet
Beginner
587 Views

Yes. It is IA-64. But our application is running on 32 bit mode.

Thanks,

Vineet

0 Kudos
TimP
Honored Contributor III
587 Views
This would not be an effective forum for discussions about peculiarities of OpenVMS, particularly for 32-bit emulation. I don't know of any compilers with extensions to define initialization of padding bytes, but the compilers dealt with on these forums don't support VMS. Likewise, alignment rules for Intel compilers wouldn't be relevant to VMS. If your question is whether a 32-bit emulator system on Itanium 64-bit VMS would change alignment issues, such speculation would be idle here.
I think Jennifer asked the question, because people sometimes get confused between IA64 (Itanium) linux and Intel64/AMD64 x86-64 linux, where 32-bit mode programs for the same operating system can run natively.
0 Kudos
goelvineet
Beginner
587 Views

Ok. What is the Intel compiler alignment rule? If compiler is pedding bytes to make structure aligned to memory boundry, does these byte are un initialized?

Why I am asking is, I working on a symbol table, and every byte of that structure make hash table key. Now if those pedded bytes are not initialize, key to hash table will change and will give wrong fetch result.

I want to know what Intel compiler's alignment rule are? No VMS.

TIA

0 Kudos
TimP
Honored Contributor III
587 Views

Alignment rules for Intel C compilers are compatible with the rules of the reference compilers which are prerequisites (Microsoft VC for Windows, gnu gcc/binutils for linux).Yourquestion seemed to be much more general than the question of padding within a struct.If you insist on writingcode which depends on details of the implementation, and may break for future versions of the reference compiler, you will have tostudy those detailsin more depth than could be described here.One would expect 32-bit VC to align data types of int or larger size to 4 byte boundaries, and 32-bit gcc to align 64-bit data types to 8 byte boundaries, subject tothe options which are available to change that behavior. If you are designing software, it seems ill-advised to make it depend on the current behavior of a particular compiler.

If you want to avoid undefined bytes within a structure, you might, for example, set up a union of an array of asimple data type such as int32_t (if you require assurance of exact 32-bit size) with whatever structure you require, and initialize the array. If your struct is assigned to allocated memory, you might use calloc() as a shortcut to initialize the entire region to int 0, but I'm no authority on the portability of it.

0 Kudos
Reply