I would like to access a single memory location with two different datatypes in the C programming language.
This is how I want it to be done:
I make a pointer and allocate 64 bits of memory for it. Then I want to access that memory by using either uint64_t
or uint8_t[8]
.
Using unsigned long long int
and unsigned char
would not be correct because sizeof(unsigned char)==sizeof(uint8_t)
is not always true.
I have a feeling that loops and copying memory is not really needed and I think that both
uint64_t abc = { 0xdeadbeefcafe1337 }
and
uint8_t[8] xyz = { 0xde, 0xad, 0xbe, 0xef, 0xca, 0xfe, 0x13, 0x37 }
look the same in memory.
Edit: But why?
I want to make it easier to do simple addition on int and I would also like to access that int value in a simple array-like fashion, one-byte time.