How does an extern “C” declaration work?

extern "C" is used to ensure that the symbols following are not mangled (decorated).


Example:

Let’s say we have the following code in a file called test.cpp:

extern "C" {
  int foo() {
    return 1;
  }
}

int bar() {
  return 1;
}

If you run gcc -c test.cpp -o test.o

Take a look at the symbols names:

00000010 T _Z3barv

00000000 T foo

foo() keeps its name.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)