C Value null when passed into function F2C

64 Views Asked by At

I am trying to run C code converted with f2c and am running into an issue.

In my MainFile.C I have:

static char fmt_4[] = "This is a very long string...";

static cilist io___94 = { 0, 6, 0, fmt_4, 0 };

printf("io___94.cierr: -%d-\n",io___94.cierr);
printf("io___94.ciunit: -%d-\n",io___94.ciunit);
printf("io___94.ciend: -%d-\n",io___94.ciend);
printf("io___94.cifmt: -%s-\n",io___94.cifmt);
printf("io___94.cirec: -%d-\n",io___94.cirec);

printf("sizeof io___94.cierr: -%lu-\n",sizeof(io___94.cierr));
printf("sizeof io___94.ciunit: -%lu-\n",sizeof(io___94.ciunit));
printf("sizeof io___94.ciend: -%lu-\n",sizeof(io___94.ciend));
printf("sizeof io___94.cifmt: -%lu-\n",sizeof(io___94.cifmt));
printf("sizeof io___94.cirec: -%lu-\n",sizeof(io___94.cirec));

s_wsfe(&io___94);

Prints:

io___94.cierr: -0-
io___94.ciunit: -6-
io___94.ciend: -0-
io___94.cifmt: -This is a very long string...-
io___94.cirec: -0-

sizeof io___94.cierr: -4-
sizeof io___94.ciunit: -4-
sizeof io___94.ciend: -4-
sizeof io___94.cifmt: -8-
sizeof io___94.cirec: -4-

s_wsfe is defined in wsfe.C from libf2c (I did not write this):

int s_wsfe(cilist *a)   /*start*/
#endif
{   int n;
    printf("a->cierr: -%ld-\n",a->cierr);
    printf("ciunit: -%d-\n",a->ciunit);
    printf("ciend: -%ld-\n",a->ciend);
    printf("a->cifmt: -%s-\n",a->cifmt);
    printf("cirec: -%d-\n",a->cirec);

    printf("sizeof a->cierr: -%lu-\n",sizeof(a->cierr));
    printf("sizeof ciunit: -%lu-\n",sizeof(a->ciunit));
    printf("sizeof ciend: -%lu-\n",sizeof(a->ciend));
    printf("sizeof a->cifmt: -%lu-\n",sizeof(a->cifmt));
    printf("sizeof cirec: -%lu-\n",sizeof(a->cirec));

    if(!f__init) f_init();
    f__reading=0;
    f__sequential=1;
    f__formatted=1;
    f__external=1;
    if(n=c_sfe(a)) return(n);
    f__elist=a;
    f__hiwater = f__cursor=f__recpos=0;
    f__nonl = 0;
    f__scale=0;
    f__fmtbuf=a->cifmt;
    f__cf=f__curunit->ufd;
    if(pars_f(f__fmtbuf)<0) err(a->cierr,100,"startio"); //Crash here
    f__putn= x_putc;
    f__doed= w_ed;
    f__doned= w_ned;
    f__doend=xw_end;
    f__dorevert=xw_rev;
    f__donewrec=x_wSL;
    fmt_bg();
    f__cplus=0;
    f__cblank=f__curunit->ublnk;
    if(f__curunit->uwrt != 1 && f__nowwriting(f__curunit))
        err(a->cierr,errno,"write start");
    return(0);
}

The results of the print statements:

a->cierr: -25769803776-
ciunit: -0-
ciend: -4323035328-
a->cifmt: -(null)-
cirec: -1-

sizeof a->cierr: -8-
sizeof ciunit: -4-
sizeof ciend: -8-
sizeof a->cifmt: -8-
sizeof cirec: -4-

cilist is defined in f2c.h:

/*external read, write*/
typedef struct
{   flag cierr;
    ftnint ciunit;
    flag ciend;
    char *cifmt;
    ftnint cirec;
} cilist;

And the problem I am running in to is that at the line indicated inside of s_wsfe the program crashes because f__fmtbuf is null, and tracking back it is because a->cifmt is null. I am expecting the value of a->cifmt to be the value of fmt_4[] from MainFile.C but it appears somewhere along the way it is getting set to null. I am not understanding why the value is null. Can someone point me in the right direction?

0

There are 0 best solutions below