onlyonemac wrote:
So first I have to tell the compiler that I want it to search the system includes directory for this one file, when I've explicitly told it *not* to use system includes.
You're using a cross-compiler, right? There's no "system includes directory" unless your compiler is targeted to a specific operating system. (Also, you shouldn't use -nostdinc, since that disables the freestanding headers in addition to the nonexistent system headers.)
onlyonemac wrote:
Then I have to hope that the file is the same/compatible on another system that might be used for compiling the code.
You don't have to worry about that. The freestanding headers are a dependency for countless C programs (even programs that are not freestanding), so any compiler that doesn't provide them or provides an incompatible version will have some obvious issues.
onlyonemac wrote:
There's no reason not to write my own when I'm writing everything else and the rest of my code is self-contained in one project that doesn't depend on whatever files the system used for compilation happens to have available.
Will you also be providing your own implementation of libgcc when GCC inevitably generates code that depends on it? Writing your own implementation of stdint.h is replacing a built-in part of the compiler in the same way.
onlyonemac wrote:
Also note that "standard header" is only relevant when you're using the "standard library". You can't just pull one header out of the standard library and expect it to always work in isolation.
Yes you can! That's why they're called "freestanding".
onlyonemac wrote:
Apart from overwriting the executable code (which is apparently bad even though I have multiple valid use cases for this), what part of looping through a section of initialised memory and replacing a specific value is undefined behaviour?
Overwriting executable code isn't necessarily bad, but a C program overwriting itself is undefined. The other piece of undefined behavior is your improperly aligned pointer conversion. A pointer to uint32_t must be aligned to the nearest sizeof(uint32_t) boundary.