#include <string.h>
#include <stdlib.h>
#include <stddef.h>
#include "adjustment.h"
Go to the source code of this file.
| LIBCOM_API size_t adjustToWorstCaseAlignment |
( |
size_t |
size | ) |
|
returns a value larger or equal than size, that is an exact multiple of the worst case alignment for the architecture on which the routine is executed.
Definition at line 25 of file adjustment.c.
27 int align_size, adjust;
28 struct test_long_word {
char c;
long lw; };
29 struct test_double {
char c;
double d; };
30 struct test_ptr {
char c;
void *p; };
31 int test_long_size =
sizeof(
struct test_long_word) - sizeof(long);
32 int test_double_size =
sizeof(
struct test_double) - sizeof(double);
33 int test_ptr_size =
sizeof(
struct test_ptr) - sizeof(void *);
34 size_t adjusted_size = size;
40 align_size = test_long_size > test_ptr_size ?
41 test_long_size : test_ptr_size;
43 align_size = align_size > test_double_size ?
44 align_size : test_double_size;
50 adjust = align_size - size%align_size;
51 if (adjust != align_size) adjusted_size += adjust;
53 return (adjusted_size);