I
Ian Collins
In this case, wouldn't »know how to call the platform's ABI«
a more appropriate wording than »know how to call C«?
The two tend to be synonymous.
In this case, wouldn't »know how to call the platform's ABI«
a more appropriate wording than »know how to call C«?
So how do you call Pascal, Fortran, (or C++) etc from C on your platform? Do
you not need to tell it that that imported function is in a different
language?
The platform interface should be language-independent. This is where a
binary interface becomes useful. (C has done a good job here in past, in
defining such interfaces, but there is often confusion; is 'long' 32-bits or
64-bits for example? gcc for Windows says 32, gcc for Linux says 64.)
But should a complex, register-based interface (I believe this might be for
x86-64) be also used as the standard when one C function calls another C
function in the same application?
Markus Wichmann said:Yeah, that's right!
Only... every function not defined "static" may be called "from the
outside". Every call to a function only declared (and not qualified
"static") but not defined may be to a foreign function.
[...] Having implemented linux's calling
conventions where you have nothing less than 7 registers that
can receive parameters
[...] those calls with embedded cals in the arguments
evaluation are a plain nightmare...
[...] Having implemented linux's calling
conventions where you have nothing less than 7 registers that
can receive parameters
I can'tbelieve Linux specifies there are 7 registers. How would it run
on a processor that didn't have 7 registers?
Nick Keighley said:[...] Having implemented linux's calling
conventions where you have nothing less than 7 registers that
can receive parameters
I can'tbelieve Linux specifies there are 7 registers. How would it run
on a processor that didn't have 7 registers?
[...] those calls with embedded cals in the arguments
evaluation are a plain nightmare...
In the Power PC you use register windows, and as far as I rememberNick Keighley said:[...] Having implemented linux's calling
conventions where you have nothing less than 7 registers that
can receive parameters
I can'tbelieve Linux specifies there are 7 registers. How would it run
on a processor that didn't have 7 registers?
[...] those calls with embedded cals in the arguments
evaluation are a plain nightmare...
Linux calling convention depends on the architecture. I guess Mr navia
is refering to the x86_64 calling convention.
jacob navia said:Le 27/11/11 13:44, André Gillibert a écrit :In the Power PC you use register windows, and as far as I rememberNick Keighley said:<snip>
[...] Having implemented linux's calling
conventions where you have nothing less than 7 registers that
can receive parameters
I can'tbelieve Linux specifies there are 7 registers. How would it run
on a processor that didn't have 7 registers?
[...] those calls with embedded cals in the arguments
evaluation are a plain nightmare...
Linux calling convention depends on the architecture. I guess Mr navia
is refering to the x86_64 calling convention.
there are more than 7 rfegisters in a window.
Now, it could be that in the ARM the situation is completely different
I do not know. Those are marginal "markets" for linux, (unless you
consider Android as linux) most users are in the main x86 distribution.
Are we talking of the same thing?
As far as I know, the C calling convention for Linux on i386, as used
in CCC, TCC and intel C compiler for user space function calls, put
function arguments on the stack pointed by ESP.
Le 27/11/11 17:34, André Gillibert a écrit :
Sorry, I forgot to specify 64 bit linux. Obviously under 32 bits
the machine can't access all the extended registers (R8 to R15)
so the conventions are very similar to windows 32 bits, as you
say, using the stack.
Since 32 bit linux is quite dated, I just didn't think that it was
necessary to specify that.
Surely compiler writers can do what they like - within their own
implementation? Calling conventions are only important when calling foreign
and OS functions, and being called from outside.
[...]Markus Wichmann said:$ uname -m -o
x86_64 GNU/Linux
$ cat test.c
#include <stdio.h>
int main()
{
printf("%d\n", sizeof(long));
return 0;
}
$ gcc test.c && ./a.out
8
$ gcc -m32 test.c && ./a.out
4
Far from dated. Most targets for embedded Linux are 32 bit (ARM, PPC).
Bogdan said:I had during an interview this question: which variables are
allocated on the stack in a function ? I am unsure how the output
variable is handled. Is this one too allocated on the stack and popped
when the function exists ?
Here is an example:
char* some_function(char c)
{
char *out = malloc(10);
return out;
}
Ian, its *Jacob*. He doesn't acknowledge the existence of any sort of
embedded development except as a tiny niche market inhabited almost
entirely by Windows-hating by Luddites.
[...]Markus Wichmann said:$ uname -m -o
x86_64 GNU/Linux
$ cat test.c
#include <stdio.h>
int main()
{
printf("%d\n", sizeof(long));
return 0;
}
$ gcc test.c && ./a.out
8
$ gcc -m32 test.c && ./a.out
4
That could have failed, since "%d" expects an int argument but you
passed it a size_t.
printf("%d\n", (int)sizeof(long));
(And "int main()" should be "int main(void)".)
Markus Wichmann said:[...]Markus Wichmann said:$ uname -m -o
x86_64 GNU/Linux
$ cat test.c
#include <stdio.h>
int main()
{
printf("%d\n", sizeof(long));
return 0;
}
$ gcc test.c && ./a.out
8
$ gcc -m32 test.c && ./a.out
4
That could have failed, since "%d" expects an int argument but you
passed it a size_t.
Oh, my bad. "%zd" it is, then.
OK, that's just a nitpick. The semantic difference between both of them
is that in the first case, the compiler doesn't complain if the caller
of main() passes additional arguments. In both cases the compiler
doesn't even get to see the caller, the only one who does that is the
linker.
What needs to be retained is that C implies (because it accepts
recursive functions) a stack like organization of the activation frames
of each function.
Sorry, but this is extremely misleading. C can and does run on
implementations with no stack. Although the C standard states in general
terms that "recursion function calls shall be permitted", the
"environmental limits" section places no constraints whatsoever on the
depth of recursion that a C implementation is required to support. So it
is perfectly acceptable to store the current hierarchy of function calls
in a fixed length list buffer, with NO notion of a stack growing and
shrinking.
I had such an implementation. int was eight bits, double 24 bits, ofSorry, but this is extremely misleading. C can and does run on
implementations with no stack.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.