Re: Making C better (by borrowing from C++)
From: Chris Croughton (chris_at_keristor.net)
Date: 02/20/05
- Next message: Chris Croughton: "Re: [C99] local VLA with dimension given by a global var?"
- Previous message: Zeljko Vrba: "Re: [C99] local VLA with dimension given by a global var?"
- In reply to: CBFalconer: "Re: Making C better (by borrowing from C++)"
- Next in thread: CBFalconer: "Re: Making C better (by borrowing from C++)"
- Reply: CBFalconer: "Re: Making C better (by borrowing from C++)"
- Reply: Dave Thompson: "Re: Making C better (by borrowing from C++)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 20 Feb 2005 11:45:23 +0000
On Sat, 19 Feb 2005 23:18:41 GMT, CBFalconer
<cbfalconer@yahoo.com> wrote:
> jacob navia wrote:
>>
>> All API functions under win32 use the _stdcall calling
>> convention. This means that the called function cleans up the
>> stack, i.e. adds to the stack before returning the space allocate
>> to make the argument frame. This means that all code for stack
>> adjustment is moved fom all call sites to the single instruction
>> in the called function.
>>
>> This can't be done with functions that receive an unknown number
>> of arguments like printf, for instance.
>>
>> In C you prototype those functions as
>> int myfn(char *,...);
>>
>> It would be impossible for such functions to clean up the stack
>> since they can't know how much was pushed, they discover it at
>> run time, and it could be perfectly legal to pass more arguments
>> than needed.
>>
>> It is needed then to have two disctinct calling conventions,
>> (there are more like fastcall where the arguments are passed in
>> registers but let's leave it at that).
>
> Things like printf, and variadic functions in general, are NOT OS
> calls (although they are a source of bugs). They are the creation
> of the C library alone. If the C compiler has a different calling
> protocol than the OS, then you simply need a collection of
> interface functions to do the conversion. Those go in the library.
Thinking about it, it's quite possible for a compiler to use two
different calling conventions automatically. If it's a variadic
function, or (in C90) has a null prototype (), the calling code pops the
parameters, otherwise the called function pops them. If a function has
a fixed number of parameters (as anything using _stdcall must do) this
this is not a problem.
If there isn't a prototype in scope at the time of the function call,
assume whichever you like and issue a warning, it's te programmer's
problem...
(Sorry jacob, you're just not inventive enough...)
Chris C
- Next message: Chris Croughton: "Re: [C99] local VLA with dimension given by a global var?"
- Previous message: Zeljko Vrba: "Re: [C99] local VLA with dimension given by a global var?"
- In reply to: CBFalconer: "Re: Making C better (by borrowing from C++)"
- Next in thread: CBFalconer: "Re: Making C better (by borrowing from C++)"
- Reply: CBFalconer: "Re: Making C better (by borrowing from C++)"
- Reply: Dave Thompson: "Re: Making C better (by borrowing from C++)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|