Stack Manipulation
Posted in 1999
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL
I have an Informix 4gl program that is being called by a C program (their object modules are associated in the Makefile). The C program is pushing two variables onto the stack and then calling a function in the 4gl. The 4gl looks like this: FUNCTION get_loan(loan, account) DEFINE account CHAR(6) DEFINE loan CHAR(16) My question: It's obvious that the C program pushed the two parameters onto the stack. How does 4gl know that the parameters are on the stack and why doesn't it have to "pop" them back off? Thanks in advance. Laurie
In article <7uo534$dhe$1@news.xmission.com>, Solgon, Laurie <lsolgon@naig.com> writes > >I have an Informix 4gl program that is being called by a C program (their >object modules are associated in the Makefile). The C program is pushing >two variables onto the stack and then calling a function in the 4gl. The >4gl looks like this: > >FUNCTION get_loan(loan, account) > DEFINE account CHAR(6) > DEFINE loan CHAR(16) > >My question: It's obvious that the C program pushed the two parameters onto >the stack. How does 4gl know that the parameters are on the stack and why >doesn't it have to "pop" them back off? Thanks in advance. > It doesn't 'know they are there'. It will pop them off the stack when you enter the function. The generated C code for the function get_loan()will contain calls pop..() functions to pop them off the stack. The number of parameters on the stack is only checked when LEAVING functions and returning values, not when ENTERING functions. >Laurie -- David Williams
David Williams wrote: > > In article <7uo534$dhe$1@news.xmission.com>, Solgon, Laurie > <lsolgon@naig.com> writes > > > >I have an Informix 4gl program that is being called by a C program (their > >object modules are associated in the Makefile). The C program is pushing > >two variables onto the stack and then calling a function in the 4gl. The > >4gl looks like this: > > > >FUNCTION get_loan(loan, account) > > DEFINE account CHAR(6) > > DEFINE loan CHAR(16) > > > >My question: It's obvious that the C program pushed the two parameters onto > >the stack. How does 4gl know that the parameters are on the stack and why > >doesn't it have to "pop" them back off? Thanks in advance. > > > > It doesn't 'know they are there'. It will pop them off the stack when > you enter the function. The generated C code for the function > get_loan()will contain calls pop..() functions to pop them off the > stack. The number of parameters on the stack is only checked when > LEAVING functions and returning values, not when ENTERING functions. True. Although when writing "C" functions that are 4GL callable you CAN check the one real argument, which is the number of arguments passed on the stack, and create a variable argument function which can be called from 4GL in different ways. I have done this and it works well. Note I believe that D4GL does not permit this 'feature' and checks for calling consistency. Art S. Kagel
In article <38107249.8854D2DC@bloomberg.net>, Art S. Kagel <kagel@bloomberg.net> writes > >True. Although when writing "C" functions that are 4GL callable you CAN >check the one real argument, which is the number of arguments passed on >the stack, and create a variable argument function which can be called >from 4GL in different ways. I have done this and it works well. Note >I believe that D4GL does not permit this 'feature' and checks for calling >consistency. > True. Even within 4gl you can pass the 'wrong' number of parameters! D4GL/4JS does not allow this. We caught a lot of problems this way! >Art S. Kagel -- David Williams