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




Not tested but see below:

On 06/06/2008, at 2:47 AM, Lim Hock-Chai wrote:

I've the following RPG export procedure, can someone help me protoype this in C?
d SndMsg PR opdesc
d SndMsg PI opdesc
d MsgInId 10 const

A message ID is only 7 bytes.

d MsgInData 32766 const options (*varsize:*nopass:*omit)
d MsgInType 10 const options(*nopass:*omit )
d MsgFile 10 const options(*nopass:*omit)
d MsgLib 10 const options(*nopass:*omit)
d MsgInQueue 10 const options(*nopass:*omit)

#pragma map (sndMsg, "SNDMSG")
void sndMsg( const char *, ... );

One required parameter, all others are optional.

To get C to pass descriptors:

#pragma descriptor (void sndMsg(*))

You can only specify a descriptor for defined parameters (i.e., not optional ones). Even though you cannot specify a descriptor for the optional parameters you will get a valid count (%parms). Not sure what will happen if you try to retrieve a descriptor for an optional parameter.


I tried below and is getting a CZM0879 compile error:

This is most likely caused by the prototype indicating a struct but the #pragma says you want a string descriptor passed. A struct is not a string.

#ifdef sndMsg_Prototype
typedef struct {
char value[10];
} sndMsg_msgID_T;


typedef struct {
char value[32766];
} sndMsg_msgData_T;

typedef struct {
char value[10];
} sndMsg_msgType_T;

typedef struct {
char value[10];
} sndMsg_msgFile_T;

typedef struct {
char value[10];
} sndMsg_msgLib_T;

typedef struct {
char value[10];
} sndMsg_msgQueue_T;


Why do this? The parameters are not structures in RPG so why force them on the C programmer? C has no concept of fixed-length fields anyway so the C programmer will have to ensure correct lengths and padding unless your RPG uses the op-desc to handle NULL-terminated strings.

You can't pass an op-desc for a structure anyway

Also C passes everything except arrays by value so passing a data structure in this manner will likely cock things up.

void
sndMsg(
const sndMsg_msgID_T *msgID,
const sndMsg_msgData_T *msgData,
const sndMsg_msgType_T *msgType,
const sndMsg_msgFile_T *msgFile,
const sndMsg_msgLib_T *msgLib,
const sndMsg_msgQueue_T *msgQueue);

Close but:
1) All parameters are required whereas the RPG prototype has only one required parameter.
2) Pointers to structs--weird from a C perspective.

#pragma map (sndMsg, "SNDMSG");

This is because RPG mono-cases procedure names. I would change that on the RPG prototype:

d SndMsg PR opdesc extproc('sndMsg')

which will cause RPG to keep the case-sensitive name so other languages won't have to map the name.

#pragma descriptor (void sndMsg(void,*))

This says no op-desc for first parm, op-desc for second, and no op- desc for any others, which is not what you want.


#endif
--
This is the C programming iSeries / AS400 (C400-L) mailing list
To post a message email: C400-L@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/c400-l
or email: C400-L-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/c400-l.



Regards,
Simon Coulter.
--------------------------------------------------------------------
FlyByNight Software OS/400, i5/OS Technical Specialists

http://www.flybynight.com.au/
Phone: +61 2 6657 8251 Mobile: +61 0411 091 400 /"\
Fax: +61 2 6657 8251 \ /
X
ASCII Ribbon campaign against HTML E-Mail / \
--------------------------------------------------------------------




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.