× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: RE: API parameter lengths
  • From: Kurt Goolsbee <K.goolsbee@xxxxxxxxxxxxx>
  • Date: Mon, 9 Jul 2001 15:30:41 -0500

        C doesn't really care about NULL terminated strings.  Some of its
functions rely on the fact that an array of characters is terminated with a
NULL but there are many other functions that just don't care.  Whether or
not your printf shows up to the NULL ("%s") or the entire buffer ("%10.10s")
depends on how you code it.  In Barbara's example there are 2 parameters and
how long they are are determined by the calling program not what is
contained in them.  You shouldn't rely on stuff passed to your C program
being NULL terminated - unless you wrote the caller.   

        > 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.


> -----Original Message-----
> From: Jim Langston [SMTP:jimlangston@conexfreight.com]
> Sent: Monday, July 09, 2001 2:50 PM
> To:   MI400@midrange.com
> Subject:      Re: API parameter lengths
> 
> 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
> +---
+---
| 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 thread ...


Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

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.