How many C compilers provide extensions which allow for a standard
implementation of the following hack?
_______________ _______________ _______________ _______________ ________
#include <stdio.h>
typedef union aligner_types_u aligner_types;
typedef struct aligner_offset_ s aligner_offset;
union aligner_types_u {
char char_;
short s_l;
int i_;
long l_;
double d_;
long double ld_;
float f_;
void *p_;
char (*fp0_) (char);
long double (*fp1_) (char, long double);
union aligner_types* uap_;
/* long long ll_; */
/* [...] */
};
struct aligner_offset_ s {
char offset;
aligner_types types;
};
#define ALIGN_MAX ( \
sizeof(aligner_ offset) sizeof(aligner_ types) \
? sizeof(aligner_ offset) - sizeof(aligner_ types) \
: sizeof(aligner_ types) \
)
int main() {
printf("ALIGN_M AX == %d\n\nhit enter to exit...\n", ALIGN_MAX);
getchar();
return 0;
}
_______________ _______________ _______________ _______________ ________
Thanks...
BTW, the ALIGN_MAX macro is needed because using a sizeof(aligner_ types)
alone is not sufficient... How many people are running platforms where
(ALIGN_MAX == 8) is true?
implementation of the following hack?
_______________ _______________ _______________ _______________ ________
#include <stdio.h>
typedef union aligner_types_u aligner_types;
typedef struct aligner_offset_ s aligner_offset;
union aligner_types_u {
char char_;
short s_l;
int i_;
long l_;
double d_;
long double ld_;
float f_;
void *p_;
char (*fp0_) (char);
long double (*fp1_) (char, long double);
union aligner_types* uap_;
/* long long ll_; */
/* [...] */
};
struct aligner_offset_ s {
char offset;
aligner_types types;
};
#define ALIGN_MAX ( \
sizeof(aligner_ offset) sizeof(aligner_ types) \
? sizeof(aligner_ offset) - sizeof(aligner_ types) \
: sizeof(aligner_ types) \
)
int main() {
printf("ALIGN_M AX == %d\n\nhit enter to exit...\n", ALIGN_MAX);
getchar();
return 0;
}
_______________ _______________ _______________ _______________ ________
Thanks...
BTW, the ALIGN_MAX macro is needed because using a sizeof(aligner_ types)
alone is not sufficient... How many people are running platforms where
(ALIGN_MAX == 8) is true?
Comment