Article View: comp.lang.c.moderated
Article #2099Re: Need help with Stacks
From: Miguel Carrasquer Vidal
Date: Thu, 29 Feb 1996 00:28
Date: Thu, 29 Feb 1996 00:28
58 lines
1808 bytes
1808 bytes
mcv@pi.net (Miguel Carrasquer Vidal) wrote: >arlyn@airmail.net (Arlyn Chesley) wrote: >>Need help with getting data onto and off of stacks >#include <stdio.h> >void stack_push(int); >void stack_pop(void); >/* warning: not ANSI C */ >void _pascal stack_push_bonus(int); OK, so I mixed up my _pascal and _cdecl calling conventions. It was 9 am and I was starting to get sleepy... Technical and platform/implementation dependent explanation follows. C functions allow a variable number of arguments [<stdarg.h>, ...] so the callee must know how to get to the _first_ parameter, and can't know how to clean up the stack after itself. On several PC compilers, the caller therefore does (3-param example): push param 3 push param 2 push param 1 call _cfunc pop 3 params ... _cfunc: ... A Pascal function, on the other hand, knows exactly what it gets. Caller simply does: push param 1 push param 2 push param 3 call PFUNC ... and the _pascal function does: PFUNC: ... pop 3 params return (actually that's a single i86 instruction: RET[F] <n_bytes_to_pop>) == Miguel Carrasquer Vidal ~ ~ Amsterdam _____________ ~ ~ mcv@pi.net |_____________||| ========================== Ce .sig n'est pas une .cig
Technical Details
Message-ID:
<4h2rvt$j3@solutions.solon.com>Path:
arc1-ca.pugleaf.net!solon.com!not-for-mailReferences:
<4gq8pl$or2@solutions.solon.com> <4gutao$i7g@solutions.solon.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail From: mcv@pi.net (Miguel Carrasquer Vidal) Newsgroups: comp.lang.c.moderated Subject: Re: Need help with Stacks Date: 28 Feb 1996 18:28:45 -0600 Organization: Planet Internet Sender: clc@solutions.solon.com Approved: clc@solutions.solon.com Message-ID: <4h2rvt$j3@solutions.solon.com> References: <4gq8pl$or2@solutions.solon.com> <4gutao$i7g@solutions.solon.com> NNTP-Posting-Host: solutions.solon.com X-Newsreader: Forte Free Agent 1.0.82