header - C - Using .h files -
i'm in process of learning c coursework assignment. 1 thing confuses me header files. i've tried find information regarding question no avail.
my question is, have 3 different .c files. convention (atleast reading sources) - each .c file has it's own .h file, e.g. parser.c has parser.h, lexer.c has lexer.h, typechecker.c has typechecker.h (if making compiler).
we go on add statement:
#include "parser.h" #include "typechecker.h"
in lexer.c file, , same other .c files (changing header files include).
instead of using convention, okay add prototypes 3 classes files 1 header, header.h, , include in 3 classes? problem 3 classes have prototypes of functions included in class, don't see problem (i'm beginner @ c wrong).
thanks.
what suggest permissible not recommended. having prototypes in 1 header cost in terms of compilation , building. try concentrate on "why header files used?". if answer refrain adding in 1 header file. header files meant modularity provide source files information need. secondly in large projects have define "private" header files used internally code , not visible outer word. ofcourse provide other users header file in order use code. not advisable put prototypes in start of learning. starter, make 1 header file per source file.
edit
if header1.h has function function1(), wherever(all source files) use function1(), add header1.h
Comments
Post a Comment