...
Code Block | ||
---|---|---|
| ||
struct big { unsigned long long ull_1; /* typically 8 bytes */ unsigned long long ull_2; /* typically 8 bytes */ unsigned long long ull_3; /* typically 8 bytes */ int si_4; /* typically 4 bytes */ int si_5; /* typically 4 bytes */ }; /* ... */ size_t skip = sizeof(unsigned long long); struct big *s = malloc(sizeof(struct big)); if (!s) { /* Handle malloc() error */ } memset(s + skip, 0, sizeof(struct big) - skip); /* ... */ free(s); |
Wiki Markup |
---|
A similar situation occurred in OpenBSD's {{make}} command \[[Murenin 07|AA. C References#Murenin 07]\]. |
Compliant Solution 2
To correct this example, the struct big
pointer is cast as a char *
. This causes skip_member
to be scaled by a factor of 1.
...