我目前有一个类似库的.c文件(将在下面显示)。我对它有两个问题:
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.
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 <signal.h> #include <sys/mman.h> #include <sys/stat.h> #include <fcntl.h> #include <semaphore.h> 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); <pre><code>free(semaforo);
}
#endif
谢谢