h0bby1 wrote:Griwes wrote:Terminology. You cannot refer to them as "files".
how should i refer to them then, to use accurate terminology, without using extra complicated syntax to handle many cases that most people will never have to deal with ever ?
Headers.
Griwes wrote:I am not sure if it's worth commenting on this. C standard states they are in <stdlib.h>, eot. The answer under the link you posted says "quite Linux specific". Hence, from these two points, IT'S NOT STANDARD, and you've put it in "standard library" section, which is utterly wrong.
Ok it's not standard. I'll change it stdlib, but it's also very possible that stdlib will include other 'files' internal to the C Library that the functions will not be defined directly in stdlib.h .
...but it's internal and has no meaning outside particular implementation.
Griwes wrote:You lack the ability to read.
First, there is no such thing as "virtual class" in C++. There are virtual member functions and virtual inheritance, but no such thing as "virtual class" - and neither of these features needs RTTI for anything.
And in majority of cases, if you need to know the actual type of a polymorphic object, you are doing it wrong. The only cases where it's not true and you actually need to do dynamic_cast for sanity are:
1) reimplementing exception handling
2) implementing things like boost.any's .as<>()
A C++ class that define only member as Pure virtual functions can be called a virtual class. If you use a base class in a program, but that the instance of the class is a class derived from it (which is the case anytime you define pure virtual method in a class), then you need RTTI to know the actual object type that the base class as been created as.
No, there is no such thing called "virtual class". I dare you to find term "virtual class" in the ISO 14882.
A class with *a* pure virtual member function is called *abstract class*. "Virtual class" has no meaning in C++.
And I still fail to see a use case for actually using RTTI, except the cases I mentioned. In proper design, outside few isolated cases, RTTI and (derived from it) dynamic_cast are non existent.
Griwes wrote:No, it's not the simplest. The simplest is to use what C and C++ standards guarantee to be available in a freestanding environment (minus things you'd want to disable yourself, like exceptions and RTTI in C++) and use a proper compiler targeting your target platform.
It's the simplest in the case you want to exclude compatibility with any other compiler, and don't care about being compatible with other compilers. Then yes you can use the compiler default, and assume any compiler who doesn't have the same default behavior is incompatible. Which is most the case not true as compiler behavior can be changed with directive. Which is really not all that complicated all together.
No. All sane targets have an ABI that a compiler knows and will always emit correct code. As soon as you start telling the compiler what you are doing, it will do it out of the box.
Griwes wrote:What. The. Actual. F*ck. Seriously, man, learn to read. Who the f*ck mentioned "linux standard"? Linux is not a widely recognized standardization organization.
Which happens to be the case, but is by no means guaranteed by anything.
it's guaranteed by the fact that if the compiler doesn't follow the standard, it will be unable to use any system functions. It was maybe the case under DOS because there was virtually no shared library, and it was very unlikely a C program would have to call function of another module, as all the system interface was handled via TSR and interupt, but in any 'modern compiler' that can compile exe able to use system api, it's pretty much guaranteed that it will follow some well defined calling convention.
You are again mentioning some weird thing you call "the standard", which is gibberish. Also, as you as an osdevver know, you can easily invoke system calls by using `int` or `syscall` or `sysenter`, and they don't follow any "calling convention" and are not invokable from C, so it doesn't matter.
Bottom line here: you don't need to follow any specific calling convention to invoke system calls.
Griwes wrote:Who the hell cares? cdecl is a sane calling convention, so it is used, as simple as that.
Yes, exactly. It's used by most C compiler that can compile exe for i386, and can be specified with function attribute. As simple as that. So it's perfectly safe to assume any C Compiler for i386 will support the cdecl call convention, with a very well defined behavior.
Can, but doing so is not really sane. In sane environment, you will have it out of the box.
Damn, I think I still have some `__attribute__((__cdecl__))` or other bullshit in my code, an artifact of times when I was as stupid as you are now...
Griwes wrote:]lol. System functions use well-defined ABI (in Linux' case, Sys V ABI), so it's obviously not a problem, but many of us do not want to follow Sys V ABI.
Well then use something else, it doesn't matter what you use if the compiler know what you use and can support it.
EXACTLY. That's the reason why you should tell the compiler which specific ABI you are targeting, either by using a cross compiler (for GCC) or by specifying -target switch (for Clang).
Griwes wrote:And Hurd is the GNU OS, hence it must be part of GCC.
Gcc and Glibc are still designed to work fine together on all the most common platform. And other compilers than gcc might not work fine with the Glibc. And other LibC might not work fine with gcc either.
Does not matter. Standard library and compiler are different entities, the same way as "Library" and "Core" are different things in both C and C++.
Griwes wrote:By using a cross compiler (using GCC) or -target switch (using Clang).
And if you don't want to use gcc ? this mean that for you,the only 'sane setup' is a setup that use gcc ?
Quite the contrary. Sane setup does not use any GNU tool, but uses LLVM, which will soon finally fully land on Windows and get a working linker.
Griwes wrote:WTF. WTF. WTF. Have you ever heard the term "POSIX"?
ok so it's POSIX specific. Have you ever heard of the term 'NT' ?
No, it's not POSIX specific. I mentioned POSIX, because you seem to think that sanity of cross compilation exist only on Linux, and that Linux is the only POSIXish OS out there.
Stop being this dumb, please.
Griwes wrote:
Additionally, MSVC is nothing more than a HOST COMPILER. Same with MinGW targetting Windows. Same with Clang compiling for Windows.
You need to seriously educate yourself.
Thanks i take care of my education, and as you mentioned yourself that you don't know visual C well, i'd rather use advise from people who are more educated about it.
Visual C can also be used as a cross compiler, actually it include cross compiler for i386, itanium, x86, arm, potentially others. Visual can produce executable for other platform than the host.[/quote]Oh yeah, it cross compiles to Windows only. And is not really able to cross compile into anything else. And is still a host compiler.
Clang is also a host compiler. And a cross compiler at the same time. One that is not limited to Windows targets.
Griwes wrote:
You obviously lie to the compiler - go on, fire your setup up and compile a program outputting value of `__linux__`. Here, `1`. Your compiler thinks its compiling for Linux, while you are not. That's lying.
I don't see why i would output the value of '__linux__' as i don't compile exe for a linux platform. I just tell the compiler everything it need to know to compile an exe for the platform i target. It's not lieing, i don't use any compiler or system specific thing. And the compiler know it.
No, it doesn't. If you use host compiler to cross compile (wtf), it will think you are compiling for the host - if it's a compiler targeting Linux, it will think it is building for Linux.
There were days when I wasn't using a cross compiler. I got bitten. The fact you haven't been bitten means nothing.
Griwes wrote:Yes. Those precautions are called "cross compiling" and "ABI contract".
ABI contract can be defined explicitly to most C compilers, you don't need a specific compiler to generate code that use a specific ABI contract.
Implicit is better than explicit.
Griwes wrote:Anything else works by accident and shall be avoided.
It doesn't work by accident.
Prove it. I expect a formal proof that a compiler cannot do something breaking your freestanding build when it thinks it's building for, say, FreeBSD (tip: it's not possible to prove it).
Griwes wrote:You do realize you have just went full rdos? You never go full rdos.
Not sure what you mean by that, but the exe format i use in the os is neither PE or ELF, and it support all the feature of import/export and relocation that can be found in a PE or ELF executable.
I mean you just went full "my specific and retarded setup is so limited it accidentally works, and my way is the only correct way despite it being broken and working by accident".
Heck, you went beyond rdos!
You are saying no-one will ever need a cross linker, because in your isolated case, you are not using a binutils linker - it's insane.
Griwes wrote:Again, what the heck is this "standard calling convention" and what widely accepted document is it described in?
Well if you don't what i'm talking about, you should educate yourself about those calling convention. You can find them in google. The calling convention for x64 are very well defined and widely accepted by any compiler that has to produce an executable that will have to use function declaration from another module compiled for x64.
They are very well defined in each individual compiler's documentation. They are recognized. That's true. And yet, your argument is still void.
You are constantly talking as if AMD64 was the only arch out there, or like I couldn't make my own compiler use whatever CC I want. No-one forbids me that. Imagine this situation: my compiler mangles symbols differently than other compilers, my linker resolves the symbols by injecting glue code between different ABIs. But it can do it only for my own OS, because my OS supports this kind of runtime linking, while other OSes don't. On those OSes, my compiler will use their calling conventions, on mine - my own calling conventions.
Now, I am writing portable libraries using just standard C++ and Boost. I cannot afford to have an __attribute__(()) here and there, as the code is supposed to be compiled using different calling conventions on different platforms. There is no other fix to this problem than to tell the compiler what target you are building for.
(Tip: the above paragraph is true even when you disregard my example setup. And yes, that setup is what I am going to implement in my OS.)
Griwes wrote:If there is no authority, compiler writers are free to do what the f*ck they want. And break your already broken way of building software.
Compiler writer are not free to do whatever they want if they want their exe to be able to use external function declaration. Which most obviously they want to. If compiler writer want to do whatever they want will calling convention, that's fine, but then the exe produced will be incompatible with most system API.
They are free to do it. Stop using this empty "if [...]" part, because it's meaningless in this discussion.
And as I've written before, system API is not invoked using C or C++ routines, but by executing `int`, `syscall`, `sysenter` or whatever the OS uses to get into kernel mode. It doesn't care about calling convention. The compiler can just recompile libc or libc++ and stop giving a **** about anything else.
Griwes wrote:
HERE WE ARE!
Let me quote this again:
And which they'd better support to a T if they want the exe they produce to be compatible with the target system.
You are lying to the compiler about the TARGET SYSTEM by not cross compiling. If it fails, it's not their problem - it's your problem, and it's so bad you even unconsciously agreed with me while trying to disagree, which proves our point.
I'm not lying to the compiler, i just tell him exactly how to compile anything, the compiler know how it should interpret and use every declaration, and if that doesn't fit the default setting it use for the host platform, then he knows about it.
lol
If you cannot see how telling the compiler "you target this specific platform" and then messing with things it's *far more knowledgeable about than you are* is lying, then I will probably rest my case.
Not to mention the fact you cannot write portable code, if you have attributes naming calling conventions everywhere, and writing non portable code (except in "do_syscall" or in the kernel) is utterly retarded.