Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <stdint.h>
- typedef struct AlignedByte_t {
- uint8_t b; /* Byte, aligned at 4-bytes border. */
- uint32_t align; /* Unused, forces structure to be aligned. */
- } AlignedByte_t;
- int
- main(void)
- {
- /*
- * Unused, allocated to obtain proper addresses.
- */
- uint8_t b;
- AlignedByte_t align_byte;
- /*
- * Pointers casting.
- *
- * Uncomment the aligned byte address taking to see how output of the
- * program will be changed.
- */
- uint8_t *var = &b; // [1]
- // uint8_t *var = &align_byte.b; // [2]
- int *pVar = (void *) var; // [3]
- /* Print values to be checked manually. */
- printf("pVar=0x%lx, sizeof(pVar)=%lu\n",
- ((unsigned long) pVar), sizeof(pVar));
- /* Check "pVar" alignment. */
- if ((((unsigned long) pVar) % sizeof(pVar)) != 0) {
- printf("\'pVar\' isn't properly aligned!\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement