you were lucky in your first example: alignment constraints on some CPUs (ex: on legacy 68000) could have segfaulted right away... Not to mention not portable code because of endianness issue.
That said, c[1][4]
isn't an array of pointers. It's a 2D array (of 4 bytes storage). So dereferencing it twice like you're doing is bound to fail (your previous technique probably "works", though).
Lying to the compiler like this isn't really an option. Also note that int
isn't guaranteed to be 4 bytes long, so better use standardized types like uint32_t
(unsigned 32-bit integer from stdint.h
)
To set data faster, you could use memcpy
, example:
uint32 v = 1;
memcpy(c,&v,sizeof(v));