Possible to compile any .c file in isolation (that is, without a main?)

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前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » CSS3 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准