Love4Boobies wrote:Freestanding C++03 (with or without TR1) implementations must provide fewer headers: <cstddef>, <limits>, <cstdlib> (see Combuster's comments), <new>, <typeinfo>, <exception>, and <cstdarg>. Perhaps passing -std=c++0x fixes things; I don't know how complete GCC's C++0x support is.
I already tried -std=c++0x before, but unfortunately it didn't change anything. It seems that I need to install (a freestanding version of) libstdc++-v3 along with my cross compiler. At least the libstdc++-v3 docs suggest that I should configure my cross compiler with "--disable-hosted-libstdcxx" and run "make all-target-libstdc++-v3 install-target-libstdc++-v3". However, even though this make command intends to
install only the freestanding headers, it nevertheless tries to
build the complete hosted library, which of course fails. I could not find a suitable workaround yet.
And what if you someday wish to port it to some architecture that GCC doesn't support but other compilers do? There are plenty of useful things that GCC can't output, such as EFI Byte Code (not that you'd want to port your OS to EFI, I'm just pointing out that GCC's not perfect).
In that case I'd have to port all the architecture dependent code to the new architecture in a way that the new compiler understands. Well, since it's a completely different and new architecture, "porting" here really means that I need to write completely new code anyway - I cannot "port" x86 CPU startup code to ARM. So it really doesn't matter to me what the existing architecture dependent code looks like - I won't reuse it for the new architecture.
But of course the architecture independent code (such as scheduler / memory manager algorithms, process and thread management...) must be ported, and this part of my kernel is indeed written completely in C++ without any architecture or compiler dependent stuff, inline assembly or whatever.
Learning calling conventions wasn't my point. My point was that changing the ABI at some point (e.g., by passing some argument to your compiler) can cause subtle bugs regardless of how you wish to write your assembly, in case inline assembly created some false sense of security. But I take it that wasn't it...
Good point.
Solar wrote:Or what if GCC changes its internals? Doesn't happen too often, but it
has happened before. Writing "unsigned int" carries
no information that you had any specific size in mind.
Relying on it having a specific size is relying on unspecified behaviour. It doesn't crash your app as certainly as de-referencing an uninitialized pointer, but it is perfectly allowed to.

And the poor sod who comes after you in maintaining your code has to deduce what you meant by "unsigned int" from the rest of the code...
I totally agree with you. That's why I intend to change all those nasty "unsigned int"s to "uint32_t"s as soon as I managed to properly integrate the freestanding C++0x headers into my cross compiler toolchain
