Re: Stack corruption and memory leak problems in c++/Fortran application



Chip Coldwell wrote:
Louis Krupp <lkrupp@xxxxxxxxxxxxxxxxxxxxxxx> writes:

The type of strlen() is 'size_t' instead of 'int'. On a 64-bit
system, strlen(code_menu) could be using eight bytes.

In fact, you are precisely right. On the Win64 architecture, size_t
is 64 bits, while both int and long are 32 bits. I'll bet this is the
cause of the four-byte memory leak.

It may be the cause of the problem, but is not likely a four
byte memory leak.

First, as James notes, the stack should be eight byte aligned
for 64 bit systems. Second, all the common C calling conventions
have the caller pop the stack. (It makes supporting C's
varargs functions much easier.)

Early 8086 calling conventions for Pascal and Fortran used a
callee-pops convention. (It saves one instruction per call,
using a special version of RET.) As C got more popular and
the need to call between languages increased, most converted
to a caller-pops convention.

-- glen

.



Relevant Pages

  • RE: Calling convention
    ... For calling conventions, cleaning stack means remove parameters info from ... I will explain cdecl, ... Microsoft Online Community Support ...
    (microsoft.public.dotnet.framework.interop)
  • Re: Calling convention
    ... For calling conventions, cleaning stack means remove parameters info from ... Microsoft Online Community Support ... nature are best handled working with a dedicated Microsoft Support Engineer ...
    (microsoft.public.dotnet.framework.interop)
  • Re: GCC front-end for FORTH?
    ... more or less the same as generating C from Forth and then compiling ... No, of course not, but Java's stack is local to the function, and Java ... and the particular calling conventions. ... I guess this question amounts to "is it possible to stop the back-end ...
    (comp.lang.forth)
  • Re: passing to C function less argument than required
    ... And the compiled binary has no problem running at all. ... be 7 argument in stack, ... I think this has to do with calling conventions. ... have an appropriate newsgroups line in your header for your mail to be seen, ...
    (comp.lang.c.moderated)
  • Re: Making C better (by borrowing from C++)
    ... This means that the called function cleans up the ... >> stack, i.e. adds to the stack before returning the space allocate ... different calling conventions automatically. ...
    (comp.lang.c)