On /windows/, Pascal-like calling conventions are used for the Win16 and
Win32 APIs. Thus on /windows/, it is the calling convention used by
/dynamic/ libraries, and programming languages and their compilers that
want to directly call functions in /dynamic/ libraries must support it.
And we have already established that on /windows/, there is no standard
for static libraries or object code formats, with every tool picking
their own methods.
On *nix, C like calling conventions are the standard, and are used by
dynamic libraries, static libraries and object code. After all, the OS
kernel is written in C, the standard libraries are written in C, and a
fair percentage of the applications are written in C. Why would you
possibly imagine that the ABI would specify something other than C
calling conventions for libraries? How would printf work? (Variable
argument functions are easily handled with C calling conventions, but
not with Pascal conventions.)
>
>> You might find that /some/ C compilers support what you refer to as
>> "PASCAL calling convention". In particular, some C compilers for
>> Windows will support it - because that was the calling convention used
>> by 16-bit Windows APIs. Similarly, 32-bit C compilers for Windows will
>> support "stdcall", because that is the convention used for 32-bit
>> Windows API. gcc also provides support for a range of calling
>> conventions on x86 even for *nix targets - it's flexible that way. But
>> it would not surprise me if *nix only compilers such as Sun's compiler
>> only support their native calling convention.
>>
>
> That's because the OS libraries use it for its libraries. That way
> those libraries can be called by any language. And although I hate to
> use Wikipedia as a reference, it is somewhat accurate in this case:
>
https://en.wikipedia.org/wiki/X86_calling_conventions
If you try reading that page, you will perhaps notice that there is no
such thing as "the OS" - there are many operating systems, and each may
have its own calling conventions for its APIs and standard libraries.
*nix systems (including Linux) use a single C calling convention for the
API and within object files. On Windows, there is one calling
convention ("stdcall") for the main APIs, but there are a variety of
other conventions in common use, and different tools use different
conventions by default.
This is why people have been discussing *nix systems, where these things
are specified and different tools all cooperate, rather than the Windows
world (and its DOS predecessor) where there is a jumble of local
conventions, often designed specifically for vendor lock-in rather than
cooperation.
>
>> As for the calling conventions Pascal can use, there has only been one
>> serious Pascal compiler - Delphi (for Windows, with a brief foray into
>> the Linux world), and it supports a range of calling conventions
>> including "cdecl".
>>
>
> Wrong again. There have been a number of "serious" Pascal compilers. I
> was using one even back in 1982 - long before Delphi. Even UCSD had a
> Pascal compiler for CPC in the late 70's. It never caught on big, but
> was used by a lot of companies (and taught in the universities) in the
> 70's and 80's. But companies went away from it for a number of (valid)
> reasons.
Yes, there have been other Pascals. But the users of Delphi and its
predecessors Borland Pascal and Turbo Pascal probably outweigh the
combined number of users for every other Pascal by a factor of a hundred.
And any Pascal implementation that is capable of accessing external
library code directly (rather than through wrappers provided by the
implementation) will have to support the calling conventions of the
target OS. On Windows, that means "stdcall" - on *nix, that means C
calling conventions. I don't know what calling conventions were used on
UCSD P-code systems - I was perhaps 9 or 10 when I used that on a VAX,
and did not get far beyond a "Hello, world" program.
>
>>
>>>
>>> stdcall is just a variation of the PASCAL calling convention.
>>>
>>>>
>>>>>>>
>>>>>>> You cannot say the same with object files, even with the PASCAL
>>>>>>> calling
>>>>>>> convention. There is no standard format, and every compiler is
>>>>>>> free to
>>>>>>> define it's own.
>>>>>>
>>>>>> This is incorrect:
>>>>>>
>>>>>>
https://refspecs.linuxfoundation.org/elf/gabi41.pdf (chapter 4)
>>>>>>
http://www.x86-64.org/documentation/abi.pdf (chapter 4)
>>>>>>
>>>>>
>>>>> Then please explain why I can't do the above.
>>>>>
>>>>
>>>
>>> No explanation?
>>>
>>
>> I have no idea why you can't do whatever it was you couldn't do "the
>> above" - I've forgotten what you are referring to here. My first guess
>> is that since you say you can't do "the above", and you seem to get
>> almost everything wrong (until you change your mind without admitting
>> it), you probably /could/ do "the above". My second guess is that just
>> because /you/ can't do it, does not mean other people can't do it. But
>> maybe, by sheer fluke, you are right and "the above" cannot be done.
>>
>
> Nope, you have a habit of skipping answers which conflict with your
> limited knowledge, and then claim you don't know what someone is talking
> about.
The only thing I can guess you meant was:
"""
Then why aren't object files compatible across compilers and operating
systems? If it were generated with gcc on Linux, I should be able to
link it in using a Microsoft compiler on Windows.
"""
But that has already been answered by others.
>
>> What is certain, however, is that there is no point in my going back in
>> the thread to figure out what "the above" is, and trying to explain
>> things to you - experience shows it is more efficient to assume you are
>> wrong, and unable and unwilling to think or learn from anything anybody
>> else says.
>>
>
> Of course not. It would conflict with your limited knowledge.
Assuming I have guessed the correct question, Scott's answer does not
"conflict with my limited knowledge" - it matches perfectly with what I
know.
(And yes, my knowledge /is/ limited, as is everybody's. But the
difference between you and everyone else in this thread is that we all
/know/ that our knowledge is limited, and are happy to look up
references, ask questions, state our uncertainties or correct our
mistakes. You, on the other hand, seem quite happy to pontificate with
a total confidence even when your claims are pure fantasy, and everyone
around you is laughing. I am sure you would make an excellent poker
player, but I am very glad I don't have to deal with you professionally.)
>
>> This is your queue to make comments about teaching pigs to sing because
>> you think it is such a clever and witty remark that we will all bow to
>> your obvious knowledge and experience (after all, you worked for IBM!).
>>
>
> Did you ever figure out how to determine at compile time whether a
> program was being built on a big endian or a little endian machine?
Um, what /exactly/ does that have to do with the topic under discussion
here?
There is no implementation-independent way to do this in C or C++. I
have never claimed otherwise. There are many implementation-dependent
ways - most compilers that target multiple platforms have pre-defined
macros that can be tested, and there are libraries (such as from boost)
that combine a range of these tests for convenience.
With C++11 or C++14 constexpr functions, it is possible that there is a
way to do it - but that would only give you limited capabilities. In
particular, to be really useful, you need the endianness to be testable
in the preprocessor.
>
> I thought not. So much for your "expertise".
>
If you can post a completely implementation-independent method of
determining the endianness of a target at compile time, using nothing
but the features required in one of the C or C++ standards (pick any one
you like), I will happily admit to being wrong in this case. The result
must be a "constant expression" - legally usable for things like
template instantiation. It is not sufficient to give an expression that
a compiler can often optimise away at compile time. Bonus points if it
is testable in the pre-processor.
You have raised this challenge - now it is up to you. If you can post
such code, your standing on Usenet will increase significantly.
Certainly I will publicise your success in c.l.c and c.l.c++, and it
will be seen even by the many people who have killfiled you. If not,
then your reputation - low as it is - will drop further.