Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

problem with compiling a c program

I am trying to compile a C program with the gcc command, it gives me the following error about 10 times:


warning: passing 'char *' to parameter of type 'unsigned char *' converts between

pointers to integer types with different sign [-Wpointer-sign]Pro


It does give me an executable file, but the file is not working properly. I had previously used the program on red hat and it worked fine.


Can any one help me figuring out how to make it work on my Mac. I have os X 10.9.5

Thanks!

iMac, Mac OS X (10.6.8)

Posted on Nov 18, 2015 11:48 AM

Reply
20 replies

Nov 18, 2015 12:12 PM in response to xyz2008

Actually, I just realized the warnings aren't all the same: here is all the warnings:


cut_fid_mf_mac2.c:42:1: warning: type specifier missing, defaults to 'int' [-Wimplicit-int]

main(argc,argv)

^~~~

cut_fid_mf_mac2.c:70:37: warning: passing 'char *' to parameter of type 'unsigned char *' converts between pointers to

integer types with different sign [-Wpointer-sign]

for(i=0;i<sizeof(f_h)/4;i++) {swabi((char*)((int *)(&f_h)+i));}

^~~~~~~~~~~~~~~~~~~~~~~~

cut_fid_mf_mac2.c:31:26: note: passing argument to parameter 'cp' here

int swabi(unsigned char *cp)

^

cut_fid_mf_mac2.c:88:52: warning: format specifies type 'int' but the argument has type 'unsigned long' [-Wformat]

printf("sizeof(short)=%d\t%d\n",(int)sizeof(short),sizeof(dfilehead));

~~ ^~~~~~~~~~~~~~~~~

%lu

cut_fid_mf_mac2.c:119:4: warning: implicit declaration of function 'mkdir' is invalid in C99

[-Wimplicit-function-declaration]

if(mkdir(argv[2],(mode_t)255+256))

^

cut_fid_mf_mac2.c:232:52: warning: format specifies type 'int' but the argument has type 'unsigned long' [-Wformat]

printf("sizeof(short)=%d\t%d\n",(int)sizeof(short),sizeof(dfilehead));

~~ ^~~~~~~~~~~~~~~~~

%lu

cut_fid_mf_mac2.c:240:38: warning: passing 'char *' to parameter of type 'unsigned char *' converts between pointers to

integer types with different sign [-Wpointer-sign]

for(i=0;i<sizeof(f_hw)/4;i++) {swabi((char*)((int *)(&f_hw)+i));};

^~~~~~~~~~~~~~~~~~~~~~~~~

cut_fid_mf_mac2.c:31:26: note: passing argument to parameter 'cp' here

int swabi(unsigned char *cp)

^

cut_fid_mf_mac2.c:246:38: warning: passing 'char *' to parameter of type 'unsigned char *' converts between pointers to

integer types with different sign [-Wpointer-sign]

for(i=0;i<sizeof(f_hw)/4;i++) {swabi((char*)((int *)(&f_hw)+i));};

^~~~~~~~~~~~~~~~~~~~~~~~~

cut_fid_mf_mac2.c:31:26: note: passing argument to parameter 'cp' here

int swabi(unsigned char *cp)

^

cut_fid_mf_mac2.c:260:44: warning: passing 'char *' to parameter of type 'unsigned char *' converts between pointers to

integer types with different sign [-Wpointer-sign]

for(j=0;j<sizeof(dblockhead)/2;j++) {swabs((char*)((short *)(data)+j));}

^~~~~~~~~~~~~~~~~~~~~~~~~~

cut_fid_mf_mac2.c:20:26: note: passing argument to parameter 'cp' here

int swabs(unsigned char *cp)

^

cut_fid_mf_mac2.c:273:44: warning: passing 'char *' to parameter of type 'unsigned char *' converts between pointers to

integer types with different sign [-Wpointer-sign]

for(j=0;j<sizeof(dblockhead)/2;j++) {swabs((char*)((short *)(data)+j));}

^~~~~~~~~~~~~~~~~~~~~~~~~~

cut_fid_mf_mac2.c:20:26: note: passing argument to parameter 'cp' here

int swabs(unsigned char *cp)

^

9 warnings generated.

Nov 18, 2015 1:49 PM in response to Keith Barkley

Thanks!

When I run the program, it does not give me the output needed, instead, it complains "NP... is too big".

The program is rather old, I first used it 10 years ago on a red hat. I don't know much about either C or any other computer programming, scripting etc, here is the original code:


/* Copyright (C) Orekhov V. Yu. (2001) Nov., Swedish NMR Centre, Goteborg.

*/

/* orov@... orov@... */


#include <stdio.h>

#include <string.h>

#include <sys/types.h>

#include <sys/uio.h>

#include "data.h"/* VNMR data header */

#define DEBUG

#include <stdlib.h>



#define EXIT_FAILURE 1


#define MAXFLAGS 200

#define MAXNP 512000

#define MAXSTR 40000


int swabs(unsignedchar *cp)

{

#ifdef LINUX

int i, bc[2]={1,0};

unsignedchar tc[2];

for(i=0;i<2;i++) {tc[i]=cp[bc[i]]; }

for(i=0;i<2;i++) {cp[i]=tc[i]; }

#endif

return(0);

}


int swabi(unsignedchar *cp)

{

#ifdef LINUX

int i, bc[4]={3,2,1,0};

unsignedchar tc[4];

for(i=0;i<4;i++) {tc[i]=cp[bc[i]]; }

for(i=0;i<4;i++) {cp[i]=tc[i]; }

#endif

return(0);

}


main(argc,argv)

int argc; char **argv;

{

dfilehead f_h,f_hw;

dblockhead b_h, *b_hp, b_hbk;

FILE *iffp,*ipfp,*offp,*opfp;

int par_flag,par_found,par_type,kwd;

long data[MAXNP];

char *pbuff,buff[MAXSTR],buff1[MAXSTR],buff2[MAXSTR],parname[128];

int narr,e1,e2,eof_f,i,j,mf_f=0,cf=1;


b_hp=(dblockhead*)data;

if(argc!=4 && argc!=7)

{

M1:

printf("program cut out 2D spectrum fid from arrayed 2D fid or multifid 2D\n");

printf("Use: %s <input.fid> <out.fid> { <array size> <n1> <n2> <param name> |<cf>}\n",argv[0]);

exit(1);

}


strcat(strcpy(buff,argv[1]),"/fid");

if(NULL==(iffp=fopen(buff,"rb")))

{ fprintf(stderr,"Can't open file %s\n",buff); exit(1);}


if(1!=fread(&f_h,sizeof(dfilehead),1,iffp))

{fprintf(stderr,"Can't read input fid header\n"); exit(1);}


/* swap bites if LINUX */

for(i=0;i<sizeof(f_h)/4;i++) {swabi((char*)((int *)(&f_h)+i));}

#ifdef LINUX

i=f_h.status;

f_h.status=f_h.vers_id; /* swap back short numbers */

f_h.vers_id=i;

#endif


if(f_h.ntraces!=1)

{printf("%s: Multifid exp f_h.ntraces= %d\n",argv[0],(int)f_h.ntraces);

mf_f=f_h.ntraces;

}

#ifdef DEBUG

printf("FID FILE HEADER; in the same order as in ddff command in VNMR\n");

printf("%5d\t%d\n",(int)(f_h.status),(int)f_h.nbheaders);

printf("%5d\t%d\n",(int)f_h.nblocks,(int)f_h.bbytes);

printf("%5d\t%d\n",(int)f_h.ntraces,(int)f_h.tbytes);

printf("%5d\t%d\n",(int)f_h.np,(int)f_h.ebytes);

printf("%5d\n",(int)f_h.vers_id);

printf("sizeof(short)=%d\t%d\n",(int)sizeof(short),sizeof(dfilehead));

#endif

if(f_h.status!=69)

{fprintf(stderr,"status in input fid = %d\n",(int)f_h.status); }

if(f_h.bbytes/sizeof(long)>MAXNP) {fprintf(stderr,"np=%ld too big\n",f_h.np); exit(1);}

if(!mf_f && argc!=7)

{ fprintf(stderr,"Error: more arguments expected for arrayed 2D\n"); goto M1;}


pbuff=argv[3];

if(1!=sscanf(pbuff,"%d",&narr)) { goto M1;}

if(narr<=0)

{fprintf(stderr,"number > 0 expected\n"); goto M1;}

if(mf_f)

{ if(narr>mf_f)

{fprintf(stderr,"Error: spectrum number %d > total num of fids %d\n",narr,mf_f); exit(1);}

cf=narr; narr=1;

} else

{

if(f_h.nblocks%narr != 0)

{fprintf(stderr,"Warning: arraydim ne delitsq na %d\n",narr);}


pbuff=strcat(strcat(strcpy(buff,argv[4])," "),argv[5]);

if(2!=sscanf(pbuff,"%d%d",&e1,&e2)) { goto M1;}

if(e1<=0 || e2 <=0)

{fprintf(stderr,"numbers > 0 expected\n"); goto M1;}

if(e2<e1) {i=e1; e1=e2; e2=i;}


pbuff=argv[6];

if(1!=sscanf(pbuff,"%s",parname)) { goto M1;}

}


if(mkdir(argv[2],(mode_t)255+256))

{fprintf(stderr,"Can't create dir %s\n",argv[2]); exit(1);}


/* make new procpar file */

if(4>strlen(argv[1]))

{fprintf(stderr,"%s - not a valid fid file name\n",argv[1]); exit(1);}

strcpy(buff,argv[1]); buff[strlen(buff)-4]=0;

strcat(buff,".fid/procpar");

if(NULL==(ipfp=fopen(buff,"r")))

{ fprintf(stderr,"Can't open file %s\n",buff); exit(1);}


strcat(strcpy(buff,argv[2]),"/procpar");

if(NULL==(opfp=fopen(buff,"w")))

{ fprintf(stderr,"Can't open file %s\n",buff); exit(1);}


#define ARRAYDIM 1

#define ARRAY 2

#define PARAM 3

#define PT_REAL 1

#define PT_STRING 2


kwd=0; i=0;

strcat(parname," ");

while(NULL!=fgets(buff,MAXSTR,ipfp)) /* for all lines in old procpar file */

{


if(kwd==ARRAYDIM)

{ sprintf(buff,"1 %d\n",(int)(f_h.nblocks*2/narr));

printf("arraydim chenged\n");

kwd=0;

}

if(kwd==ARRAY)

{ sprintf(buff,"1 \"phase\"\n");

printf("array chenged\n");

kwd=0;

}

if(kwd==PARAM)

{

switch(par_type)

{

case PT_REAL: sprintf(buff,"1 0\n");

kwd=0;

break;

case PT_STRING:

if(i==0)

{

sscanf(buff,"%d",&i);

sprintf(buff,"1 \"n\"\n");

if(EOF==fputs(buff,opfp))

{ fprintf(stderr,"Can't write to file %s\n",buff); exit(1);}

}

else

{

if(i==1) kwd=0;

}

break;


default: printf("Unknown parameter type %d\n",par_type); exit(1);

}

if(i<2) printf("%s chenged\n",parname);

}

if(!mf_f) /* do not chenge procpar for multifid exp */

{

if(buff==strstr(buff,"arraydim "))

{ kwd=ARRAYDIM;

}

if(buff==strstr(buff,"array "))

{ kwd=ARRAY;

}

if(buff==strstr(buff,parname))

{ kwd=PARAM;

par_type=-1; i=0;

if(1!=sscanf(buff,"%*s%*s%d",&par_type))

puts(buff);

}

}


/* printf("kwd=%d i=%d\n",kwd,i); */

if(i==0)

{ if(EOF==fputs(buff,opfp))

{ fprintf(stderr,"Can't write to file %s\n",buff); exit(1);}

} else i--;

}


/* make empty text file */

strcat(strcpy(buff,argv[2]),"/fid");

if(NULL==(offp=fopen(buff,"wb")))

{ fprintf(stderr,"Can't open file %s\n",buff); exit(1);}


strcat(strcpy(buff,argv[2]),"/text");

if(NULL==(opfp=fopen(buff,"w")))

{ fprintf(stderr,"Can't open file %s\n",buff); exit(1);}

fclose(opfp);


/* write new fid file header */

f_hw=f_h;

if(mf_f)

{

f_hw.ntraces=1;

f_hw.bbytes-=f_hw.tbytes*(mf_f-1);

}

else

{

f_hw.nblocks/=narr/2;

}


#ifdef DEBUG

printf("NEW FID FILE HEADER; in the same order as in ddff command in VNMR\n");

printf("%5d\t%d\n",(int)(f_hw.status),(int)f_hw.nbheaders);

printf("%5d\t%d\n",(int)f_hw.nblocks,(int)f_hw.bbytes);

printf("%5d\t%d\n",(int)f_hw.ntraces,(int)f_hw.tbytes);

printf("%5d\t%d\n",(int)f_hw.np,(int)f_hw.ebytes);

printf("%5d\n",(int)f_hw.vers_id);

printf("sizeof(short)=%d\t%d\n",(int)sizeof(short),sizeof(dfilehead));

#endif

/* swap bites if LINUX */

#ifdef LINUX

i=f_hw.status;

f_hw.status=f_hw.vers_id; /* swap back short numbers */

f_hw.vers_id=i;

#endif

for(i=0;i<sizeof(f_hw)/4;i++) {swabi((char*)((int *)(&f_hw)+i));};


if(1!=fwrite(&f_hw,sizeof(dfilehead),1,offp))

{fprintf(stderr,"Can't write to out fid file\n"); exit(1);}


/* swap back bites if LINUX */

for(i=0;i<sizeof(f_hw)/4;i++) {swabi((char*)((int *)(&f_hw)+i));};

#ifdef LINUX

i=f_hw.status;

f_hw.status=f_hw.vers_id; /* swap back short numbers */

f_hw.vers_id=i;

#endif


eof_f=1;

printf("Wait ...\n");

while(eof_f) /*to the end of fid file */

for(i=0;i<narr;i++) /* for one array cycle */

{

if(1!=fread((char*)data,f_h.bbytes,1,iffp)) { eof_f=0; break;}

/* swap bites if LINUX */

for(j=0;j<sizeof(dblockhead)/2;j++) {swabs((char*)((short *)(data)+j));}


if(b_hp->status != f_hw.status)

{

fprintf(stderr,"Warning: wrong status in fid %d+1 status=%d\n",b_hbk.index,

(int)b_hp->status);

*b_hp=b_hbk; b_hp->index+=1; b_hbk.index+=1;

} else b_hbk=*b_hp;


if(i+1 != e1 && i+1 != e2 && mf_f ==0 ) continue;/* skip blocks in aarayed 2D

*/


/* swap bites if LINUX */

for(j=0;j<sizeof(dblockhead)/2;j++) {swabs((char*)((short *)(data)+j));}


if(1!=fwrite((char*)data,sizeof(dblockhead),1,offp)) /* write block header */

{fprintf(stderr,"Can't write to out fid file\n"); exit(1);}


/* printf("e1,e1, %d %d i+1 %d sizeof(dblockhead)+(cf-1)*f_hw.tbytes %d %d

%d %d\n",e1,e2,i+1, */

/*

sizeof(dblockhead)+(cf-1)*f_hw.tbytes,sizeof(dblockhead),f_hw.bbytes,f_h.bbytes) \

; */


if(1!=fwrite((char*)data+sizeof(dblockhead)+(cf-1)*f_hw.tbytes,f_hw.tbytes,1,off\

p))

{fprintf(stderr,"Can't write to out fid file\n"); exit(1);}

}


exit(0);

}

problem with compiling a c program

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.