This page is a draft. Please help enhancing it by adding lines and filling tables. Comments at the bottom of the text are also welcome.
This is just a quick array to recall some of the specifics of the architectures found in the Debian project.
feature |
alpha |
any-amd641 |
arm |
avr32 |
hppa |
any-i3862 |
ia64 |
s390 |
s390x |
?x32 |
||||||||||
size of short |
2 |
2 |
2 |
2 |
2 |
2 |
2 |
2 |
2 |
2 |
2 |
2 |
2 |
2 |
2 |
2 |
||||
size of int |
4 |
4 |
4 |
4 |
4 |
4 |
4 |
4 |
4 |
4 |
4 |
4 |
4 |
4 |
4 |
4 |
||||
size of long |
8 |
8 |
4 |
8 |
4 |
4 |
4 |
8 |
4 |
4 |
4 |
4 |
8 |
4 |
4 |
4 |
8 |
|||
size of long long |
8 |
8 |
8 |
8 |
8 |
8 |
8 |
8 |
8 |
8 |
8 |
8 |
8 |
8 |
8 |
8 |
||||
alignment of long long |
? |
- |
8 |
8 |
4 |
- |
4 |
? |
? |
? |
? |
- |
? |
4 |
8 |
? |
||||
size of float |
4 |
4 |
4 |
4 |
4 |
4 |
4 |
4 |
4 |
4 |
4 |
4 |
4 |
4 |
4 |
4 |
||||
size of double |
8 |
8 |
8 |
8 |
8 |
8 |
8 |
8 |
8 |
8 |
8 |
8 |
8 |
8 |
8 |
8 |
||||
size of long double |
163 |
16 |
8 |
16 |
8 |
8 |
12 |
16 |
12 |
8 |
163 |
163 |
16 |
163 |
8 |
16 |
16 |
|||
alignment of long double |
? |
16 |
? |
8 |
? |
4 |
- |
4 |
? |
? |
? |
? |
8 |
? |
4 |
16 |
? |
|||
size of data pointer |
8 |
8 |
4 |
8 |
4 |
4 |
4 |
8 |
4 |
4 |
4 |
4 |
8 |
4 |
4 |
4 |
8 |
|||
max alignment |
8 |
8 |
4 |
8 |
? |
? |
? |
4 (16) |
8 |
? |
? |
8 |
? |
? |
? |
? |
4 |
? |
? |
|
unaligned access OK |
no |
yes |
no |
yes |
yes |
yes |
no |
yes |
no |
yes |
no |
yes |
yes |
yes |
no |
no |
yes |
? |
||
endian |
little |
little |
little |
little |
big |
big |
little |
little |
big |
big |
little |
big |
big |
big |
big |
little |
little |
little |
||
char |
s |
s |
u |
u |
u |
s |
s |
s |
s |
s |
u |
u |
u |
s |
s |
s |
s |
|||
stack grows |
down |
down |
down |
down |
down |
up |
down |
down |
down |
down |
down |
down |
down |
down |
down |
down |
down |
|||
func param location |
regs |
regs |
regs |
regs |
? |
? |
stack |
regs |
stack |
regs |
regs |
regs |
regs |
regs |
regs |
regs |
? |
|||
func return ptr location |
reg |
stack |
reg |
reg |
? |
? |
stack |
reg |
stack |
reg |
reg |
? |
? |
reg |
reg |
stack |
? |
|||
page size(s) |
8K |
4K, 2M |
4K |
4K, 64K |
? |
? |
4K, 2M/4M |
? |
4K |
4K-64K |
? |
4K |
? |
4k |
4K, 2M |
? |
C/C++ Preprocessor Symbols
Generally, GNU C tends to define the symbol
__arch__
A list of some common arch-specific symbols can be found on the Pre-defined Architecture Macros page.
Signedness
When programming in C, variables can be signed or unsigned.
Example:
unsigned char c; |
explicit unsigned, 0 <= c <= 255 |
signed char c; |
explicit signed, -128 <= c <= 127 |
char c; |
implicit (un)signedness, depending on architecture |
To force a signedness, either declare it explicitly or use the gcc command line option -f(un)signed-char. The gcc defaults differ only due to optimisation. Other compilers may not have this issue.
Obtaining this information
via a special tool
#include <alloca.h> #include <endian.h> #include <stddef.h> #include <stdio.h> static void test_size_align(const char *name, size_t size, size_t align) { printf("sizeof(%s) = %zu\n", name, size); if (size != align) printf("alignment(%s) = %zu\n", name, align); } #define TEST_SIZE_ALIGN(type, name) \ struct test_align_##name { char a; type b; }; \ test_size_align(#type, sizeof(type), offsetof(struct test_align_##name, b)) static void test_endian(void) { #if __BYTE_ORDER == __LITTLE_ENDIAN printf("byte order = little endian\n"); #elif __BYTE_ORDER == __BIG_ENDIAN printf("byte order = big endian\n"); #endif } static void test_char(void) { if ((int)(char)-1 == -1) printf("char signedness = signed\n"); else if ((int)(char)-1 == 255) printf("char signedness = unsigned\n"); } static void test_stack(void) { void *a = alloca(8); void *b = alloca(8); if (a > b) printf("stack = grows down\n"); else printf("stack = grows up\n"); } int main(void) { TEST_SIZE_ALIGN(short, short); TEST_SIZE_ALIGN(int, int); TEST_SIZE_ALIGN(long, long); TEST_SIZE_ALIGN(long long, long_long); TEST_SIZE_ALIGN(float, float); TEST_SIZE_ALIGN(double, double); TEST_SIZE_ALIGN(long double, long_double); TEST_SIZE_ALIGN(void *, pointer); test_endian(); test_char(); test_stack(); return 0; }
via autoconf
AC_INIT(archtest, 0.1) AC_CHECK_SIZEOF(short) AC_CHECK_SIZEOF(int) AC_CHECK_SIZEOF(long) AC_CHECK_SIZEOF(long long) AC_CHECK_SIZEOF(float) AC_CHECK_SIZEOF(double) AC_CHECK_SIZEOF(long double) AC_CHECK_SIZEOF(void*) AC_C_BIGENDIAN() AC_C_CHAR_UNSIGNED()