Re: Passing variable # of args to C funcs
Posted in 1994
>From: andrewm@ccfadm.eeg.ccf.org (Martin Andrews) >Subject: Passing variable # of args to C funcs >Date: Fri, 1 Apr 1994 15:16:57 GMT >X-Informix-List-Id: <news.6139> > >The 4gl stack structure lets you write C functions that can >receive a variable number of arguments, but the 4gl compiler >complains when two calls to a function from the same file have >a different number of arguments. Otherwise variable number of >arguments seems to work fine. Is there a way to keep the >4gl compiler from complaining about different usages within >a single file? > >I am using 4gl compiler version 4.10. I just created bug B26400 to address this. The gist of what the bug report says is that "-z" is supposed to work, and it does in I4GL-RDS, and it would in I4GL if you could get the argument passed to the phase 1 compiler ($INFORMIXDIR/lib/fglc to you). You will need to modify the c4GL script as installed so it recognizes '-z' at all. I've attached a context diff for the 4.11.UC1 version of c4gl which fixes the problem. The equivalent changes can be made in any other version very simply. Yours, Jonathan Leffler (johnl@informix.com) #include <disclaimer.h> =========================================================================== B26400: C4GL DOES NOT PASS THE -Z FLAG TO THE PHASE 1 COMPILER WHICH NEEDS IT The C4GL script in 4.1x (VRF 4.10.UC2, 4.11.UC1, 4.12.UC1, 4.12.UD1, 6.00.UD1A2) does not pass the -z option to the phase 1 compiler, so it is not possible to compile the code below without error using C4GL. By contrast, the FGLPC (RDS) compiler will complain when invoked without the -z flag, and will accept the code when given the -z flag. If invoked directly, the phase 1 compiler (FGLC in 4.1x, I4GLC1 in 6.00) also will complain about this code without the -z flag, and will accept it with the -z flag. FUNCTION f() CALL a(3, 1, 2, 3) CALL a(2, 99, 98) CALL a(1, -12) CALL a(0) END FUNCTION *** /usr/local/informix/4.11.UC1/bin/c4gl Wed Mar 31 16:29:15 1993 --- c4gl Sun Apr 3 14:38:29 1994 *************** *** 17,23 **** : : : Title: c4gl ! : Sccsid: @(#)c4gl 8.1.1.1 3/2/93 15:17:11 : Description: : : c4gl - call fglc for each .4gl file --- 17,23 ---- : : : Title: c4gl ! : Sccsid: @(#)c4gl 8.1.1.1 3/2/93 15:17:11 -- Revised for '-z' option : Description: : : c4gl - call fglc for each .4gl file *************** *** 27,33 **** if [ $# -lt 1 ] then ! echo "Usage: c4gl [-Vaec] [-ansi] [-anyerr] [-otherargs]" echo " source.4gl ... [othersrc.c ...] [otheresql.ec ...] " echo " [otherobj.o ...] [yourlib.a ...] [-o outfile] [-l lnkflags]" echo "" --- 27,33 ---- if [ $# -lt 1 ] then ! echo "Usage: c4gl [-Vaecz] [-ansi] [-anyerr] [-otherargs]" echo " source.4gl ... [othersrc.c ...] [otheresql.ec ...] " echo " [otherobj.o ...] [yourlib.a ...] [-o outfile] [-l lnkflags]" echo "" *************** *** 39,44 **** --- 39,45 ---- echo " -c Preprocess & compile only, no linking" echo " -otherargs Other arguments are passed to the C compiler" echo " -o Next argument is program name" + echo " -z Allow variable numbers of arguments to functions" echo " -l <lnkflags> Pass remaining flags to linker" exit 1 fi *************** *** 52,57 **** --- 53,59 ---- ANSIFLG= ANYFLG= BFLG= + ZFLG= for F do *************** *** 62,73 **** -ansi ) ANSIFLG=$F ;; -anyerr ) ANYFLG=$F ;; *.4gl ) FBASE=`basename $F .4gl` ! $FGLC $BFLG $ANSIFLG $ANYFLG $F TEMP=$? if [ $TEMP -eq 0 -o $TEMP -eq 6 ] then --- 64,78 ---- -ansi ) ANSIFLG=$F ;; + -z) + ZFLG=$F + ;; -anyerr ) ANYFLG=$F ;; *.4gl ) FBASE=`basename $F .4gl` ! $FGLC $BFLG $ZFLG $ANSIFLG $ANYFLG $F TEMP=$? if [ $TEMP -eq 0 -o $TEMP -eq 6 ] then =========================================================================== PS: This message, I suppose, is a little more nearly official than most I send -- but it still isn't guaranteed. PPS: One test script, assuming the source code above is in b26400.4gl: # @(#)Notes on bug B26400 # Run the following commands (Bourne/Korn Shell): # You can use: sh README I=${INFORMIXDIR:=/usr/informix} export INFORMIXDIR P14=$I/lib/fglc P16=$I/lib/tools/i4glc1 fglpc b26400.4gl || echo "Failed correctly" # Should always fail fglpc -z b26400.4gl && echo "Passed correctly" # Should never fail if [ -x $P16 ] then # Version 6.00 installation (P14 exists, but is a shell script) $P16 b26400.4gl || echo "Failed correctly" # Should always fail $P16 -z b26400.4gl && echo "Passed correctly" # Should never fail elif [ -x $P14 ] then $P14 b26400.4gl || echo "Failed correctly" # Should always fail $P14 -z b26400.4gl && echo "Passed correctly" # Should never fail else echo "Cannot find phase 1 compiler ($P14 or $P16)" >&2 exit 1 fi c4gl -c b26400.4gl || echo "Failed correctly" # Should always fail c4gl -c -z b26400.4gl && echo "Passed correctly -- BUG FIXED" || echo "** BUG ** should not fail"