Diana Deer
Diana Deer

Reputation: 35

Google test: strange behaviour when testing C code

I`m trying to test my C code by using Google test(never worked with it before) but looks like it thinks that I wanna test C++ code

23: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
     str->data = malloc(buf_size + 1);
33: error: invalid conversion from 'void*' to 'char*' [-fpermissive]
         char *new_begin = malloc(buf_size + 1);

My testing file (if instead of including source file I include header it fails during testing (or maybe even before)

#include <gtest/gtest.h>
extern "C" {
#include "../lib/scr/c_string.c"
}

All in all, I just changed code for

str->data = (char*)malloc(buf_size + 1);

as it works on C++. Thankfully, nothing crashed :)

Upvotes: 0

Views: 390

Answers (1)

Justin Otto
Justin Otto

Reputation: 584

extern "C" does not turn the included source code into C it specifies a linkage convention to use for the declarations which occur within the block you have included your file into.

In other words, your C file contents are being copied into a C++ source file, and compiled as C++, with C linking conventions.

Upvotes: 2

Related Questions