1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
|
// SPDX-License-Identifier: MIT
/*
* Print architecture characteristics
* written by Jan Engelhardt, 2011
*/
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <wchar.h>
#ifdef _WIN32
# include <winsock2.h>
# include <ws2tcpip.h>
# define SIZET_FMT "I"
#else
# include <netinet/in.h>
# define SIZET_FMT "z"
# define HAVE_LOFF_T 1
#endif
struct x16 {
uint8_t a;
uint16_t b;
};
struct x32 {
uint8_t a;
uint16_t b;
uint32_t c;
};
struct x64 {
uint8_t a;
uint16_t b;
uint32_t c;
uint64_t d;
};
#define p(type) q(type, type)
#define q(type, vname) \
extern int SIZEOF_##vname, ALIGNOF_##vname; \
int SIZEOF_##vname = sizeof(type), ALIGNOF_##vname = __alignof__(type);
#define t(type) \
printf("%14s %7" SIZET_FMT "u %7" SIZET_FMT "u\n", \
#type, sizeof(type), __alignof__(type))
p(char);
p(short);
p(int);
p(long);
q(long long, longlong);
p(float);
p(double);
q(long double, longdouble);
q(void *, voidptr);
q(void (*)(void), funcptr);
p(intptr_t);
p(wchar_t);
p(size_t);
p(off_t);
#ifdef HAVE_LOFF_T
p(loff_t)
#endif
p(uint8_t);
p(uint16_t);
p(uint32_t);
p(uint64_t);
q(struct x16, x16);
q(struct x32, x32);
q(struct x64, x64);
#ifdef HAVE_MODE_T
p(mode_t);
#endif
p(time_t);
q(struct timespec, timespec);
q(struct sockaddr, sockaddr);
q(struct sockaddr_in, sockaddr_in);
q(struct sockaddr_in6, sockaddr_in6);
#ifndef WITHOUT_MAIN
int main(void)
{
printf("%14s %7s %7s\n", "TYPE", "SIZEOF", "ALIGNOF");
t(char);
t(short);
t(int);
t(long);
t(long long);
t(float);
t(double);
t(long double);
t(void *);
t(void (*)(void));
t(intptr_t);
t(size_t);
t(wchar_t);
t(off_t);
#ifdef HAVE_LOFF_T
t(loff_t);
#endif
t(uint8_t);
t(uint16_t);
t(uint32_t);
t(uint64_t);
t(struct x16);
t(struct x32);
t(struct x64);
#ifdef HAVE_MODE_T
t(mode_t);
#endif
t(time_t);
t(struct timespec);
t(struct sockaddr);
t(struct sockaddr_in);
t(struct sockaddr_in6);
t(struct sockaddr_storage);
return EXIT_SUCCESS;
}
#endif
|