|
A question on this Barbara, > #include <stdio.h> > main(int argc, char *argv[]) > { > int i; > for (i = 1; i < argc; i++) > { > printf("arg %d %s\n", i, argv[i]); > } > } > ===> CALL pgm ('abc def ghi' 'zyx') > arg 1 abc def ghi > arg 2 zyx Say the string 'abc def ghi' was in a variable. Say that I changed the spaces x'40' to nulls x'00'. Then passed them like this: > ===> CALL pgm (&PARM1 &PARM2) Would the C program then report this as 4 parameters or still 2? I know that C uses null terminated strings, and am fairly sure that the arguments are put onto the stack instead of the pointers, which makes me think C would see 4 parameters, but I'm not sure what argc would report. Also, if it was 2 parameters obviously the printf would only show the initial 'abc' anyway stopping at the null terminator. Regards, Jim Langston Me transmitte sursum, Caledoni! bmorris@ca.ibm.com wrote: > > >Date: Mon, 9 Jul 2001 10:54:23 -0500 > >From: "Alexei Pytel" <pytel@us.ibm.com> > > > >CALL command does not do this. > >C PEP (program entry point) procedure does. For every main() in C, > compiler > >generates a PEP (you may see it if you do DSPMOD on C module). This PEP > >procedure among other things will scan for first blank in each parameter > >and create null-terminated string for each parameter. > ?This makes it very difficult to pass non-character parameters to C main(). > > Alexei, that is not true; where did you hear that? If you call a C program > with a parameter of 'abc def ghi', it will get one parameter. The > null-termination is indeed done by the call command. > > Calling a C program from another program is not difficult. In that > case, the C program receives the same parameters that the caller passed > because the PEP doesn't do any processing on the parameters except to > build the argv array from the parameters that are passed to the program. > But it just copies the parameter pointers into the array of pointers; it > doesn't do anything with the parameter data. > > A test: > > #include <stdio.h> > main(int argc, char *argv[]) > { > int i; > for (i = 1; i < argc; i++) > { > printf("arg %d %s\n", i, argv[i]); > } > } > ===> CALL pgm ('abc def ghi' 'zyx') > arg 1 abc def ghi > arg 2 zyx > > Barbara Morris +--- | This is the MI Programmers Mailing List! | To submit a new message, send your mail to MI400@midrange.com. | To subscribe to this list send email to MI400-SUB@midrange.com. | To unsubscribe from this list send email to MI400-UNSUB@midrange.com. | Questions should be directed to the list owner/operator: dr2@cssas400.com +---
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.