As far as i know, whenever we use a code compiled in c in c++ we have to specify a linkage convention for example,
extern "C" {
void func1(void);
void func2(int, double);
}
The use of extern "C"
says that (lack of reference link):
it should be linked according to the C linkage convention. All functions in standard C library are written in this way like (stdio.h, cstdio, stdlib.h, ...)
Now coming to system headers like unistd.h
, fcntl.h
, if you view the contents, it is just a normal C header without any extern "C"
surrounding them.
Now, when used in c++ code it is compiling without any errors.
These are my questions:
- Why it is linking without any errors.
Should i include the header like this so it works every time.
extern "C" { #include }