logoalt Hacker News

vbezhenarlast Monday at 10:35 PM1 replyview on HN

C++ code compiles to a different function names in object file (name mangling). You probably need to put a lot of ugly `#ifdef __cplusplus extern "C" {` boilerplate in your headers, otherwise C and C++ files will not compile together.


Replies

winocmlast Monday at 11:01 PM

Don't forget the infamous pattern used in some C projects too:

  struct foo decl = {
    .member = /* ... */
    .next = &(struct nested_pointer) {
        .nested_member = /* ... */,
    },
    .array = (struct nested_array[]) {
      [0] = { /* ... */ },
    }
  };
This pattern does not work in C++ as the nested declarations become temporaries.