views:

157

answers:

3
+1  A: 

Perhaps the layout in memory of the two versions of the struct isn't the same? I tried this in gcc:

#include <stdio.h>

struct WTO_PARM {
    unsigned short len;
    unsigned short code;
    char *text;
};

int main()
{
    struct WTO_PARM moo = { 4+11,0,"hello" };
    printf("size %zu struct %p string %p\n", sizeof(struct WTO_PARM),&moo,moo.text);
    return 0;
}

Here are the results:

size 8 struct 0x22cce0 string 0x402000

However, if I change the type of the text parameter to char[80], the results change to:

size 84 struct 0x22cc80 string 0x22cc84

The WTO instruction likely expects the string to be packed right into that struct.

Matt Kane
+1 correct the struct
Robert
The "layout in memory" of the two structs is the same - it's the structs that are different. One has a pointer (and this pointer points _somewhere outside_ the struct) while the other has an array (and arrays are _wholly contained_ where they are declared - in functions, structs, etc).
Chris Lutz
A: 

Why can't you compile the IBM sample? It works fine for me - perhaps you could show us your compiler parms and error messages?

Nighthawk
+1  A: 

The IBM example worked for me (under Z/os 1.9) but I had to add a pragma to set the codepage: on top of the example: #pragma filetag("IBM-500") The compiler did not accept the [ and ] in the char text[80]; I've tried to change char text[80] into char *text as well but I got the same strange result as you.

Bob Leysen