× 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: Variable length MODS
  • From: boldt@xxxxxxxxxx
  • Date: Wed, 18 Apr 2001 08:07:30 -0400
  • Importance: Normal


Jim wrote:
>Actually, James, I have used that structure definition in C.
>Although the syntax may be a bit off.
>
>char * array[];
>
>maybe?  Although I think
>
>char array[];
>
>is actually legal.  A pointer to an array of char of undetermined
>size. Which is exactly what I was talking about.
>
>C gurus wish to clarify?

If you don't know C, the following explanation will either help
you understand it better, or will scare you away from the
language:

Pointers and arrays are treated almost identically in C.  You can
declare something as 'char arr1[10];' or as 'char *arr2;' and the
only difference is that storage (auto or static) is allocated for
the first but not the second.  (Also, you can't assign a pointer
value to the first.)  Everything else is the same.  Both 'arr1[x]'
and '*(arr1+x)' are valid C expressions and both mean exactly the
same.  Likewise valid and equivalent are 'arr2[x]' and '*(arr2+x)'.
C treats both 'arr1' and 'arr2' as both arrays and pointers.

The definition 'char array[]' is legal as a function parameter,
but not as a variable.  As a function parameter, that definition
is exactly equivalent to 'char *array' - pointer to character.

Regarding 'char *array[]', well, that's valid as a function
parameter (but not as an auto or static variable), and is
equivalent to 'char **array'.  That is, a pointer to a pointer to
character.  (Double indirection is quite useful in linked list
processing - we do it all the time in the ILE RPG compiler!)

Confused yet?  Yes?  Good!

Now then, in C, if you want a character array of undetermined size,
code it as 'char *array;' and then explicitly allocate the amount
of storage you want using 'array=malloc(size);'.

One more point about array handling in C, note that since 'arr[x]'
and '*(arr+x)' are exactly equivalent, array bounds checking is
meaningless in C.

(Once you get used to it, it is a fun language.)

Cheers!  Hans

Hans Boldt, ILE RPG Development, IBM Toronto Lab, boldt@ca.ibm.com

+---
| This is the RPG/400 Mailing List!
| To submit a new message, send your mail to RPG400-L@midrange.com.
| To subscribe to this list send email to RPG400-L-SUB@midrange.com.
| To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.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.