...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <assert.h>
void func(void) {
char c = 'x';
int *ip = (int *)&c; /* This can lose information. */
char *cp = (char *)ip;
assert(cp == &c); /* Will fail on some conforming implementations */
/* ... */
} |
...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <assert.h>
void func(void) {
char c = 'x';
int *ip = (int *)&c; /* This can lose information. */
char *cp = (char *)ip;
assert(cp == &c); /* Will fail on some conforming implementations */
/* ... */
} |
...
Code Block | ||||
---|---|---|---|---|
| ||||
#include <stdalign.h> /* For alignas() */
#include <assert.h>
void func(void) {
alignas(int) char c = 'x'; /* Align c to the alignment of an int */
int *ip = (int *)&c;
char *cp = (char *)ip;
assert(cp == &c); /* Both cp and &c point to equally aligned objects. */
/* ... */
} |
Risk Assessment
...