3

As far as i know, whenever we use a code compiled in in 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 code it is compiling without any errors.

These are my questions:

  1. Why it is linking without any errors.
  2. Should i include the header like this so it works every time.

    extern "C" { #include }

Joseph D.
  • 11,804
  • 3
  • 34
  • 67
Atul
  • 546
  • 4
  • 16

0 Answers0