Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- unsigned int getSizeInCharsAlignedToInt(unsigned int iSizeInChars)
- {
- return (iSizeInChars+(sizeof(int)-1))/sizeof(int)*sizeof(int);
- }
- int main (int argc, char **argv){
- printf("sizeof int: %zu\n", sizeof(int));
- printf("(0): %d\n",getSizeInCharsAlignedToInt(0));
- printf("(1): %d\n",getSizeInCharsAlignedToInt(1));
- printf("(2): %d\n",getSizeInCharsAlignedToInt(2));
- printf("(3): %d\n",getSizeInCharsAlignedToInt(3));
- printf("(4): %d\n",getSizeInCharsAlignedToInt(4));
- printf("(7): %d\n",getSizeInCharsAlignedToInt(7));
- printf("(8): %d\n",getSizeInCharsAlignedToInt(8));
- printf("(14): %d\n",getSizeInCharsAlignedToInt(14));
- printf("(16): %d\n",getSizeInCharsAlignedToInt(16));
- printf("(31): %d\n",getSizeInCharsAlignedToInt(31));
- return 0;
- }
- /*
- output:
- sizeof int: 4
- (0): 0
- (1): 4
- (2): 4
- (3): 4
- (4): 4
- (7): 8
- (8): 8
- (14): 16
- (16): 16
- (31): 32
- */
Advertisement
Add Comment
Please, Sign In to add comment