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



Hi Aaron,

> To go along with Scott and Joe's comments I am fairly certain you cannot
> use a VARYING field as a parm to a C API.

You can use VARYING as long as it's either an options(*string) or a CONST
parameter.

> This is because the first two chars of the variable contain it's length
> and since C doesn't support RPG's version of VARYING length fields it
> thinks those first two bytes are part of the file path/name.

That's true, but if you use options(*string) or CONST (or VALUE, though C
doesn't usually use VALUE for strings) then the compiler will
automagically convert the string to the right format.

If you're just passing a pointer to a string, then you can use VARYING,
but you have to add 2 to the pointer value.

If you're passing a fixed-length alphanumeric string by reference without
using CONST, then you cannot use VARYING.

> I may be wrong, but I struggled with this some time ago and I think that
> is what I came up with.

You're not completely wrong, but you're wrong in this particular case.
The first parameter to open() should be defined with options(*string) and
therefore it works brilliantly with VARYING variables.

But, even with APIs like write() where you usually pass a pointer to the
variable that you're intending to write to disk, I still prefer the use of
VARYING fields.  It allows you to code like this:

         len = write(fd: %addr(myVaring) + 2: %len(myVaring));

(the "+2" skips over the 2 bytes where the length is stored)

which, in my opinion, anyway, is nicer (and runs faster!) than:

         len = write(fd: %addr(myFixed): %len(%trimr(myFixed));

Hope that helps...

As an Amazon Associate we earn from qualifying purchases.

This thread ...

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.