Re: calling convention stdcalll and cdecl call
- From: "Igor Tandetnik" <itandetnik@xxxxxxxx>
- Date: Fri, 18 Jul 2008 16:34:51 -0400
Alf P. Steinbach <alfps@xxxxxxxx> wrote:
* Igor Tandetnik:
printf("%d", 1, 2);
For what it's worth the above example (1) has undefined behavior
Not true. C99 standard explicitly covers this case:
7.19.6.1/2 The fprintf function writes output to the stream pointed to
by stream, under control of the string pointed to by format that
specifies how subsequent arguments are converted for output. If there
are insufficient arguments for the format, the behavior is undefined.
*If the format is exhausted while arguments remain, the excess arguments
are evaluated (as always) but are otherwise ignored.* (emphasis mine).
In 7.19.6.3, printf is defined in terms of fprintf.
I don't have C89 standard handy at the moment, but I'm pretty sure it
contains the same wording.
(2) states that I somehow have ownership of an addressing convention,
which is incorrect and misleading and just idiotic, but typical
weaseling rhetoric
What do you mean by "addressing convention"? I'm not familiar with the
term. Since I don't know what it is, I don't make any statements about
its ownership.
All I state is this. The above call is perfectly valid according to the
standard, so a conforming C compiler has to support it. To execute this
call, three arguments have to be pushed onto the stack, and then later
three arguments have to be popped off. Under cdecl calling convention,
both operations are done by the caller, who of course knows how many
arguments there are.
You seem to suggest that it is perfectly reasonable to require the
callee to clean up the stack instead. I'd like to see what mechanism you
propose to make this possible, other than having the caller pass
additional information to the callee, above and beyond the three
arguments (e.g. the total size of all arguments).
If the mechanism you'd like to propose does involve passing additional
information to the function, then I agree with you in that such a
calling convention would indeed be possible. However, I don't see how it
would be an improvement over cdecl. And since cdecl is already happily
supported by existing tools, it is hard to expect compiler authors to
begin supporting something that is worse. What would be the point?
On the other hand, stdcall is an improvement over cdecl, however minor.
It shifts one machine instruction from the call site (where it has to be
repeated for each call) to the callee (where it exists only once per
function, not once per every place in the program where the function is
called). In exchange for this slight efficiency gain, it loses the
ability to support variadic functions.
and (3) asks a question you already got complete
demonstration code for, and based on that example you yourself
pointed out one possible answer to that question.
Right. My point is _not_ that the technique your sample demonstrates is
impossible. Just that it's unnecessarily complicated and pointless, and
so it's not at all surprising that it's not supported by mainstream
tools.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
.
- References:
- Re: calling convention stdcalll and cdecl call
- From: Igor Tandetnik
- Re: calling convention stdcalll and cdecl call
- From: Alf P. Steinbach
- Re: calling convention stdcalll and cdecl call
- From: Igor Tandetnik
- Re: calling convention stdcalll and cdecl call
- From: Alf P. Steinbach
- Re: calling convention stdcalll and cdecl call
- From: Igor Tandetnik
- Re: calling convention stdcalll and cdecl call
- From: Alf P. Steinbach
- Re: calling convention stdcalll and cdecl call
- From: Igor Tandetnik
- Re: calling convention stdcalll and cdecl call
- From: Alf P. Steinbach
- Re: calling convention stdcalll and cdecl call
- Prev by Date: Re: calling convention stdcalll and cdecl call
- Next by Date: Re: api to create new thread
- Previous by thread: Re: calling convention stdcalll and cdecl call
- Next by thread: Re: calling convention stdcalll and cdecl call
- Index(es):
Relevant Pages
|