Remember that C11 is a programming language, so is a specification (it is not a software). Read n1570 draft.
How to specifically increment by 3, and what is the recommended approach? It seems that using a (char *) cast might be the way to go?
That is very probably some undefined behavior (in general). On some computers, it might "work" (but very slowly, because you make an unaligned access, read about data structure alignment). You could try;
ptr = (uint32_t*)((char*)ptr + 3);
But you should avoid coding like that (it is some ugly non-portable code, with bad smell). On many computer architectures or instruction sets, you are likely to get a bus error or a segmentation fault. On some computers where that is not crashing, it might be a non-atomic operation (you might not be sure of what would happen if that code was scheduled so got a context switch or some interrupt inside). Read also about sequence points & pointer aliasing.
So I recommend not coding like that, even if it happens to apparently work (a future optimizing compiler might do things differently) on your machine. If you need to code such bad things, be sure to at least add a big fat warning in some comment. Perhaps use volatile
(or some atomic operations). Be sure to check the emitted assembler code (e.g. with gcc -O -fverbose-asm -S
).
(a less ugly solution might be to copy byte by byte)
Take time to read Lattner's blog on What every C programmer should know about undefined behavior; you really need to read that carefully.
(not getting any warnings, and getting some apparently working code, is the worst kind of undefined behavior; you should be very scared, and you are not scared enough!)
Since you are thinking from some piece of code in assembler, you might consider using an asm
statement. Read Using Assembly Language with C.