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



On Wed, 9 Oct 2002, Steve Richter wrote:
>
> Its just a hunch of mine.  C relies on null term strings so I am speculating
> that ILE handles them efficiently.
>


Yes, I'm familiar with C, since I program in it on Unix machines.
Normally, though, when you pass a string in C you pass a pointer.  I don't
think I've EVER seen a C function that passes a string by value.

In fact, it's very difficult to pass a string by value in C.  I'm not
evern sure that you CAN without using a data structure...

Normally you'd do something like this:

       int myfunc(const char *input, char *output, int size);

  Which means that the input is a pointer to a null-terminated string,
  passed as "const" (so you can't change it in the function)  the output
  is also a pointer to a null-terminated string.   This would be
  equivalent to the following RPG prototype:

    D myfunc          PR            10I 0
    D  input                          *   value options(*string)
    D  output                         *   value options(*string)
    D  size                         10I 0 value

See? You're passing the strings by pointer, i.e. by reference.  So you
really can't compare it to a varying field passed by value.

To pass by value in C you'd have to do something like:

#include <stdio.h>

struct stuff {
   char mystring[32000];
};

int myfunc(struct stuff t) {
     printf("%s\n", t.mystring);
     return 0;
}

int main(void) {
    struct stuff b;
    strcpy(b.mystring, "This got passed by value!");
    return 0;
}


So, that's about the same thing as:

    D myfunc          PR            10I 0
    D   string                   32000A   value

Even though the string is "variable length" (i.e. null-terminated) in C,
it still copies all 32000 bytes.   So I would expect it to actually be
less efficient than the RPG counterpart.   I suppose I could write up a
benchmark and try it...  but this message is already getting long :)

At any rate, nobody EVER passes strings by value in C.  So, I SERIOUSLY
doubt you'd find it more efficient than RPG.




As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

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.