Re: "character (len = :), allocatable :: foo" ?

From: Jugoslav Dujic (jdujicREMOVE_at_uns.ns.ac.yu)
Date: 11/06/03


Date: Thu, 6 Nov 2003 10:42:01 +0100

Richard Maine wrote:
| ajpspragg@rhmtech.co.uk (Andy Spragg) writes:
|
|| On Wed, 5 Nov 2003 17:37:46 +0100, "Jugoslav Dujic"
|| <jdujicREMOVE@uns.ns.ac.yu> wrote:
|
||| character, allocatable :: foo (:)
||| and
||| character (len = :), allocatable :: foo
||| is/will be indeed different...
||
|| Eek! Does this mean that it is not possible for me properly to use a
|| stdcall with a pointer to char argument unless I know in advance how
|| long it needs to be? Could this be the source of my stack inflation?
|
| Character argument passing is...interesting, particularly in
| mixed language environments. I know nothing about Microsoft
| calling conventions (stdcall vs whatever that other one was).

OK, just FYI, here's a summary of stdcall vs. cdecl calling conventions.
Stdcall is also known as PASCAL, but that term is deprecated. Cdecl is
classic C calling convention used on Unix. Stdcall differs in the following
aspects:

1) It's the duty of called routine to clean the stack. In cdecl, caller
  cleans the stack (returns the stack pointer to the value before the call).
2) Name mangling is different. In stdcall, it's always
   _routinename@nargs4
   where nargs4 is 4*number of arguments = number of bytes pushed on the
   stack.

I think both implementations use left-to-right argument pushing (I think
old PASCAL flavor used right-to-left). Also, by default, scalars are
passed by value, and arrays & strings by reference in both conventions.
Stdcall is tad (one or two cycles) faster and produces slightly smaller
code (calls cleaning is in one place per routine).

The Good Thing about it is that it doesn't allow mismatch in number of
arguments (name mangling will cause a linker error -- even if not, stack
will be screwed badly as the callee would free more arguments than the
caller has sent). It's also a bad thing for porting old codes which
used argument count mismatch deliberately (e.g. map a string argument
to a BYTE array).

-- 
 Jugoslav
___________
www.geocities.com/jdujic


Relevant Pages

  • Re: Problems with big modules of subroutines
    ... So if you substitute an integer for a real, or a character for 2 ... What you are describing is the IA-32 Windows STDCALL calling ... convention, defined by Microsoft, which has a naming convention that ... be popped off the stack when the routine returns. ...
    (comp.lang.fortran)
  • Re: How to - SDI
    ... because Pascal does not use the same linkage as __stdcall. ... "PASCAL", in Win16, means that it pushes arguments right to left and the called function ... parameters from the stack. ... freeing up another computational register. ...
    (microsoft.public.vc.mfc)
  • Re: StdCall vs. CDecl
    ... I don't understand why "leaving arguments on the stack" is benign. ... If the caller expects the callee to "clean up the stack" (that is, restore the stack pointer to the value it had before the caller pushed a call frame onto the stack), then I would expect the caller to be thoroughly messed up after the call returns and the caller tries to get to its own data on the stack. ... That's for calling a cdecl function as stdcall. ...
    (microsoft.public.dotnet.framework.interop)
  • Re: _stdcall and __cdecl
    ... arguments, while _stdcall does not. ... This page has a nice summary of the different calling conventions and their ... for example, if you create a thread with _beginthreadex, the thread function ...
    (microsoft.public.dotnet.languages.vc)
  • Re: calling convention stdcalll and cdecl call
    ... the compiler can somehow figure out how the function accesses its parameters, it can figure out how many there are, and pop the stack correctly without any additional information from the caller. ... int find{ ... This is similar to how it must take some action for a __stdcall member function, ...
    (microsoft.public.vc.language)