Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
bzt wrote:FYI, it looks like Clang can be compiled to support builtins the same way as gcc does, using so called VARIANTs, read the comment on this test case for example.
The comment about variants is discussing using the same test code to test two different built-in functions, where one function is tested when VARIANT is defined, and the other is tested when VARIANT is not defined, such as in this test case. Built-in functions are always available in Clang, the same way they're always available in GCC. Both compilers will assume your hosted implementation follows the standard C library API unless you tell them otherwise with -fno-builtin. Both compilers will warn you if you try to redefine a built-in function with the wrong signature.
Octocontrabass wrote:Built-in functions are always available in Clang, the same way they're always available in GCC.
Now this is not true, see the example I've liked before. There's a Makefile for gcc and another for Clang, so you can test the same source with both easily.
Octocontrabass wrote:Both compilers will assume your hosted implementation
That's the thing, we are not talking about hosted implementation, because you can't write a libc in a hosted environment, you must use freestanding.
Now I see why are you confused.
Octocontrabass wrote:Built-in functions are always available in Clang, the same way they're always available in GCC.
Now this is not true, see the example I've liked before. There's a Makefile for gcc and another for Clang, so you can test the same source with both easily.
I didn't say they will always be inlined, just that they are always available. When they're not inlined, they behave as an ordinary function call. Did you try changing -O2 to -Os in your makefile yet?
bzt wrote:That's the thing, we are not talking about hosted implementation, because you can't write a libc in a hosted environment, you must use freestanding.
Why? As long as you're careful to avoid including old headers, I see no reason why you couldn't.
Octocontrabass wrote:Why? As long as you're careful to avoid including old headers, I see no reason why you couldn't.
Because, in a hosted environment, all the header files and all the identifiers from chapter 7 are reserved. Defining a function called "printf" is undefined behavior in hosted mode, since the identifier is reserved. Creating a "stdio.h" is undefined for the same reason. Etc. pp.