Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

ENTERPRISE C ARRAYS

Name: Anonymous 2010-11-26 14:39

ENTERPRISE C

typedef struct{
    int *bars;
    int n;
}foo;

int addBarToFoo(foo *f,int k)
{
    int i;
    foo *old        =    f;
    if(!(f            =    calloc(f->n+1,sizeof(foo))))
        return FALSE;
    for(i=0;i<f->n;++i)
        f->bars[i]    =    old[i];
    f->bars[f->n]    =    k;
    free(old);
    return TRUE;
}



could one of you experts optimize this even further?

Name: Anonymous 2010-11-26 15:51

>>1
typedef struct{int *bars;int n;}foo;int addBarToFoo(foo *f,int k){int i;foo*old=f;if(!(f=calloc(f->n+1,sizeof(foo))))return FALSE;for(i=0;i<f->n;++i)f->bars[i]=old[i];f->bars[f->n]=k;free(old);return TRUE;}

Don't change these.
Name: Email:
Entire Thread Thread List