I am getting the following error and warning for a script:
rfixpro.c:7:14: error: conflicting types for ‘malloc’ char *p, malloc(); ^ rfixpro.c:9:7: warning: assignment makes pointer from integer without a cast [enabled by default] p = malloc(n); This is part of a program I am trying to install by using make. I never used C++ befor so please excuse my ignorance. I tried to run the script without the 'include' lines, but this produces other warnings. I therefore also post the entire script.
#include <stdio.h> #include <stdlib.h> char * emalloc (n) unsigned n; { char *p, malloc(); p = malloc(n); if (p == NULL) printf ("out of memory\n"); return p; } int rfixpro (ns, pH, beta, pKint, ida, g, cutoff, cs, tot) int ns; /* Number of titratable sites */ float pH; float beta; /* 1 / kT */ float pKint[]; /* Intrinsic pK of sites (input) */ int ida[]; /* ida=1 for cation 2 for anion (input) */ float g[]; /* site - site interaction matrix (input) */ float cutoff; /* Cutoff value for fixing sites (input) */ float cs[]; /* degree of protonation of sites (output) */ float *tot; /* total protonation (output) */ { int nsr; /* Number of sites in reduced set */ int *fprot; /* = 1 or 0 if fixed prot or deprot = -1 if unfixed */ int *rmap; /* rmap[i] = full set index of reduced set site i */ int *fmap; /* fmap[i] = reduced set index of full set site i */ /* fmap[i] = -1 if i not in reduced set */ float *pKintr; /* Intr. pKs for reduced set */ int *idar; /* Reduced form of ida */ float *gr; /* Reduced form of g */ float *csr; /* Reduced form of cs */ int i; fprot = (int *) emalloc ((unsigned) ns * sizeof (int)); rmap = (int *) emalloc ((unsigned) ns * sizeof (int)); fmap = (int *) emalloc ((unsigned) ns * sizeof (int)); pKintr = (float *) emalloc ((unsigned) ns * sizeof (float)); idar = (int *) emalloc ((unsigned) ns * sizeof (int)); gr = (float *) emalloc ((unsigned) ns*ns * sizeof (float)); csr = (float *) emalloc ((unsigned) ns * sizeof (float)); pfix (ns, pH, beta, pKint, ida, g, cutoff, &nsr, fprot, rmap, fmap, pKintr, idar, gr); tc (nsr, pKintr, idar, gr, pH, beta, csr); *tot = 0.0; for (i=0; i<ns; ++i) { if (fmap[i] != -1) cs[i] = csr[fmap[i]]; else cs[i] = (float) fprot[i]; *tot += cs[i]; } free ( (char *) fprot); free ( (char *) rmap); free ( (char *) fmap); free ( (char *) pKintr); free ( (char *) idar); free ( (char *) gr); free ( (char *) csr); return (nsr); }
mallocfunction is declared in the<stdlib.h>header file. Code usingmallocshould include that header file and not declare it itself. Which is done (still in pre-ANSI way) in theemallocfunction.out of memoryto console, but then continues like everything went fine, resulting in undefined behaviour.