bbe9
![]() |
|
|
|
|
|||||||
| Userland Programming & Scripting C, C++, Python, Perl, Shell, etc. |
![]() |
|
|
Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Hi all,
Code:
main()
{
int d[4];
int b = 55;
int c = 34;
int e = 23;
return 0;
}
Is there a gcc option which tell it not to leave such spaces? Also, the second is on a powerpc (OS: OpenBSD) and the first is a x86 machine running FreeBSD. Both are 32 bit processors. Thanks. |
|
#2
|
|||
|
|||
|
I would think that on the 2nd system (powerpc) the compiler tries to keep the stack boundary aligned at 4 times 32bits equaling 128bits. On i386 there may not be the same requirements. There seems to be an option that might be what you're looking for, this is an i386 and amd64 specific option:
Code:
-mpreferred-stack-boundary=num
Attempt to keep the stack boundary aligned to a 2 raised to num
byte boundary. If -mpreferred-stack-boundary is not specified, the
default is 4 (16 bytes or 128 bits).
![]() Which version of gcc(1) you used in the FreeBSD case? The manual page I quoted is from version 4.6. |
|
#3
|
|||
|
|||
|
Quote:
EDIT: I've seen that the stack-boundary option changes how the stack is setup, For eg: Code:
0x0804843d <main+13>: push %ecx 0x0804843e <main+14>: sub $0x20,%esp 0x08048441 <main+17>: mov $0x0,%eax 0x08048446 <main+22>: add $0x20,%esp . Please let me know if the above interpretation is correct. If it is correct then how can I make the compiler leave space after/before the variables and not between the array and variables. Thanks. Last edited by asp5; August 19th, 2012 at 22:13. |
|
#4
|
||||
|
||||
|
#pragma pack(n) where n may be 2, 4, 8, ... is what you are looking for.
For performance reasons, you might want to enclose only some structs with this directive. Anyway, the most portable option would be to use unions where possible. Best regards Rolf |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Declaration of Variables | Sarouel | Userland Programming & Scripting | 8 | October 14th, 2012 09:19 |
| Kernel Space / User Space bi-directional communication | perleo | FreeBSD Development | 3 | July 23rd, 2012 07:23 |
| ssh variables | eeluve | Web & Network Services | 1 | July 11th, 2012 08:59 |
| [Solved] fsck command for oversized RAID arrays? | ghostcorps | System Hardware | 6 | November 29th, 2010 22:37 |
| [Solved] How do you reestablish zpool/ZFS arrays after reinstalling the OS? | palmboy5 | Installing & Upgrading | 11 | August 14th, 2010 07:33 |