Please enable JavaScript.
Coggle requires JavaScript to display documents.
Lect 13 #include directives - Coggle Diagram
Lect 13 #include directives
include dir
tell preproceessor insert contents of another file into source code at the point where #include dir found
format: #include<,,>:preprocessor search for predetermined directory path
imclude".." :preprocessor look for header file in the same directory as sou;rce file
Content of header file
useful macros
dat. struct
func def
tested func only
reusing func
def of const
Directive of conditional compilation
Conditional preprocessor directives
switch On/Off prog segment
handle dependencies on operating system
Exampl: prog writes results into a file FILE *fout ; char fname[100]; #ifdef LINUX #define DATADIR "/home/alex/"
else #define "C:\user\alex" #endif
Conditional compilation
Ex: Calc area or parametr of a circle #ifdef AREA_PER
area=r
r
PI;
pritnf(:aerea %f\n",area);
else
perimeter=2
r
PI;
printff("perimeter %f\n",perimeter);
endif
Stucture of header file
if header file has been included before, FALSE, prog qiuts
Ex: headedr file for complex data n functiojns acting on complex numvbers complex.h
ifndef_COMPLEX_H
def_COMPLEX_H
typedef struct{
float real;
float imag;
}COMLEX;
COMPLEX cmplxsum(COMPLEX c1, COMPLEX c2){
COMPLEX sum;
sum.real=c1.real + c2.real;
sum.imag=c1,imag+ c2.imag;
return sum;
}
endif
Prevent insert header file > once
Compulsory lines: header.h
ifndef
COMPLEX.H
define
COMPLEX.H
endif
iNLINE FUNCTION
(execution of f-like macro doesnt perform type checking n conversion; having jjoverheads)
=> COMBINED ADVANTAGES OF func n macro
execution
request to compiler but compiler make decision
same as macros(code inserted into line wthout causing overheads)
Exmple: #define MAX(x,y) ((x)>(y))?(x):(y) int a=3.4,b=4.5,c;
c=MAX(a,b);
OR
inline int max(int a,int b){return a>b?a:b;}
int a=3.4,b=4.5,c;
c=max(a,b);