M
mdh
I am not sure if this is directly related to C or the compiler (Xcode)
I am using...but I will ask and see.
I have started creating unique C files ( .c and .h) so that I can
reuse some of the functions when doing the exercises in K&R.
The code below is created in , for example, foo.c. Main.c contains the
directive #included <stdio.h> yet unless I include the same directive
in foo.h, the error and warning will not go away. My understanding,
( or rather misunderstanding ) was that once declared in main, one
need not "redeclare" in foo.h. If this is unique to Xcode, I will ask
there.
Thank you.
/*foo.h*/
/* #include <stdio.h> */ <<<uncommenting this removes the error
and warning.
char *alloc (int );
void afree(char *p1);
/*foo.c*/
#include "foo.h"
#define BUFFSIZE 120
static char allocbuff[BUFFSIZE];
static char *p = allocbuff; /*assigns ptr to buffer*/
char static *pend = allocbuff + BUFFSIZE;
char *alloc ( int n) {
if ((p + n) < pend){
p +=n;
return p - n;}
else
return NULL; /* error: 'NULL' undeclared (first use in this
function) *****ERROR HERE
}
void afree(char *p1){
if ( p1 >= allocbuff && p1 < pend)
p=p1;
else
printf( "Error: Space requested is not available") ; /* "warning:
incompatible implicit declaration of built-in function 'printf' */
***WARNING HERE
}
I am using...but I will ask and see.
I have started creating unique C files ( .c and .h) so that I can
reuse some of the functions when doing the exercises in K&R.
The code below is created in , for example, foo.c. Main.c contains the
directive #included <stdio.h> yet unless I include the same directive
in foo.h, the error and warning will not go away. My understanding,
( or rather misunderstanding ) was that once declared in main, one
need not "redeclare" in foo.h. If this is unique to Xcode, I will ask
there.
Thank you.
/*foo.h*/
/* #include <stdio.h> */ <<<uncommenting this removes the error
and warning.
char *alloc (int );
void afree(char *p1);
/*foo.c*/
#include "foo.h"
#define BUFFSIZE 120
static char allocbuff[BUFFSIZE];
static char *p = allocbuff; /*assigns ptr to buffer*/
char static *pend = allocbuff + BUFFSIZE;
char *alloc ( int n) {
if ((p + n) < pend){
p +=n;
return p - n;}
else
return NULL; /* error: 'NULL' undeclared (first use in this
function) *****ERROR HERE
}
void afree(char *p1){
if ( p1 >= allocbuff && p1 < pend)
p=p1;
else
printf( "Error: Space requested is not available") ; /* "warning:
incompatible implicit declaration of built-in function 'printf' */
***WARNING HERE
}