XDR routines crash in QNX 4.25

My apologies if this is not the correct newsgroup.
I’m a newcomer to QNX 4.25. I’m having difficulty using the XDR routines. In particular, I create a XDR “memory stream” using xdrmem_create(), but as soon as I attempt to access it with xdr_getpos() I get a segmentation violation. The QNX 4 “knowledge base” at qnx.com mentions a similar problem, and says that XDR programs must be compiled with -Wc,-ei so I am using this flag. Nonetheless the following “simple” program gives segmentation fault when I run it. Any advice would be much appreciated.

#include <stdio.h>
#include <rpc/xdr.h>
#include <netinet/in.h>

int main(int argc, char **argv) {

// Allocate XDR state buffer - allocate lots of extra
unsigned int outBufSize = 1000;

char *outBuf = (char *)malloc(outBufSize);

XDR xdrStream;
xdrmem_create(&xdrStream, outBuf, outBufSize, XDR_ENCODE);

fprintf(stderr, “TEST xdr_getpos()\n”);
int pos = xdr_getpos(&xdrStream); // Seg fault occurs here!!!
fprintf(stderr, “xdr_getpos() OK\n”);

fprintf(stderr, “TEST xdr_setpos()\n”);
if (!xdr_setpos(&xdrStream, 0)) {
fprintf(stderr, “xdr_setpos() failed!\n”);
}
else {
fprintf(stderr, “xdr_setpos() OK\n”);
}

return 0;
}

Regards,
Tom

That’s nasty one.

Had you read the documentation on -Wc you would have seen that it is use to pass option to the C compiler, but your program is in C++. You need to use -WC,-ei, to pass the option down to the C++ compiler.

[quote=“mario”]
ThatAh, nice catch - that fixed it. And I note that one must compile the rpcgen-erated ‘C’ file with -Wc,-ei, and my C++ application which utililzes it with -WC,-ei. Yes, I was confused!

Thanks!