I know this question has been asked elsewhere but reading the already given answers is not helping me. My code is ridiculously simple yet I cannot compile it. I’m writing code to build a stack.
Here is my stack.h:
#ifndef GUARD
#define GUARD
struct Stack {
struct Stack* next;
int data;
};
extern bool isempty (struct Stack*);
#endif
here is my stack.c:
#include <stdio.h>
#include <stdlib.h>
#include "stack.h"
bool isempty (struct Stack* st) {
return (st == NULL);
}
The compiler keeps on complaining about this line:
extern bool isempty (struct Stack*);
The contents of my main.c are irrelevant (for now it just returns 0). Does anyone understand what I am doing wrong?
The type
boolis generally not available in C.If your compiler supports C99, you can add
to make it available, though.
UPDATE: Use of C99 is, in my opinion, not exactly pervasive in C programs “in the large”, no. Most boolean values, such as function returns, are represented as
int, which is how it has been solved classically. For arrays, you’d be quite likely to find them represented as bits packed into e.g.unsigned int, rather than e.gbool a[32];.But, in an interview context, I think it would be pretty nice for a candidate to write the above without flinching. It was standardized 13 years ago, after all.