I currently have a "library-like" .c file (that'll be shown below). I have 2 questions about it:
1. If I want to see if it compiles well for itself, how can I do it? If I try to gcc it, it will always give a "no main" error, which makes sense, but raises the problem of knowing if a given .c file will compile well or not in "isolation". Can I safely conclude that if the only error raised by the compiler is the "no main" one, my file is fine? An example of where compiling .c files in isolation could be nice would be to determine which includes are in excess, in here.
2. Is there a point in a simple file like this to define a header with its method / struct declarations and then have such tiny .c file with the code implementation in it?
#ifndef SEMAFOROS
#define SEMAFOROS
#include
#include
#include
#include
#include
typedef struct {
sem_t* id;
char* nome;
} Semaforo;
inline void lock(Semaforo* semaforo) {
sem_wait(semaforo->id);
}
inline void unlock(Semaforo* semaforo) {
sem_post(semaforo->id);
}
Semaforo* criarSemaforo(char* nome) {
Semaforo* semaforo = (Semaforo*)malloc(sizeof(Semaforo));
semaforo->id = sem_open(nome, O_CREAT, 0xFFFFFFF, 1);
semaforo->nome = nome;
}
void destruirSemaforo(Semaforo* semaforo) {
sem_close(semaforo->id);
sem_unlink(semaforo->nome);
free(semaforo);
}
#endif
Thanks
以上就是Possible to compile any .c file in isolation (that is, without a main?)的详细内容,更多请关注web前端其它相关文章!