The C declaration of a pointer is ambiguous. A char * means (at least) two different things, 1) a pointer to a single char, or 2) a pointer to the first element of an array. A C programmer, of course, had decided the meaning in his mind when he wrote the code. However, powerRPC (or a maintainer of other people's code too?) is not able to guess this implicit meaning. The C programmer usually writes a comment such as ``this is a string", so the reader of his code knows what a char* really means. We must do the same thing for powerRPC.
In powerRPC IDL, a T* will always be interpreted as a pointer to a single object of type T. To declare a ``pointer array", you must used the following syntax,
Notice the position of ``[size_attrib]" is before the identifier ptr. The C declaration corresponding to the above is simply T *ptr, obtained by replacing the ``[size_attrib]" before the identifier ptr with a *.
We have mentioned about the size attributes for fixed arrays. For ``pointer array", we should have an additional attribute, maxsize to specify the maximum number of elements, using the maxsize = expression syntax within the subscript operator []. You may also specify the maximum size with a integer constant, without using the maxsize = expression syntax. Example:
struct msg_t2 { int maxlen; char [size = (msg? strlen(msg)+1 : 0), maxsize=maxlen] msg; char [256] msg2; char msg3[256]; };
Notice that we did not specify the size attribute for msg2, in this case powerRPC will take the maxsize, which is 256, as the size. However, you must specify at least one of the sizes for an array, otherwise an error will be reported by powerRPC.
The C declaration of the above is
struct msg_t2 { int maxlen; char * msg; char * msg2; char msg3[256]; };
It is your responsibility of to make sure that msg and msg2 are initialized and pointing to allocated memory before using it as RPC arguments. You must be very careful, or a memory fault will occur, for example, the declaration claims member msg2 is an array of 256 elements, so powerRPC will try to faithfully deliver 256 chars. If msg2 was a NULL pointer, a fault would be inevitable.