codeplea/tinyexpr

Invalid conversion compiler warnings

kornkaobat opened this issue · 8 comments

te_expr ret = malloc(size);
88 31 D:\ ...\Mywork\Cpp\Starter\tinyexpr.c [Error] invalid conversion from 'void
' to 'te_expr*' [-fpermissive]
case TE_FUNCTION7: case TE_CLOSURE7: te_free(n->parameters[6]); / Falls through. /
102 69 D:\ ...\Mywork\Cpp\Starter\tinyexpr.c [Error] invalid conversion from 'void*' to 'te_expr*' [-fpermissive]
...
183 1 D:\ ...\Mywork\Cpp\Starter\tinyexpr.c [Error] invalid conversion from 'double ()(double)' to 'const void' [-fpermissive]

Call code:

int main()
{
	std::cout << "Input arithmetic calculation: \n";
	std::string calc;
	std::cin >> calc;
    double result = te_interp("calc", 0);
    std::cout << "Result = ";
    std::cout << result << '\n';
    return 0;
}

Looks like you're compiling tinyexpr as C++. You need to compile it as C code, then link it into your C++ project.

Also, this line is not what you want:

double result = te_interp("calc", 0);

To pass a C++ string to a C function, you would do something like this:

double result = te_interp(calc.c_str(), 0);

Same error, but I think it could be from C & C++ incompatibilities.

This is the full code then;

#include <stdio.h>
#include <math.h>
#include < iostream >
#include < string >
#include <stdlib.h>
#include <D:\ ... \Mywork\Cpp\Starter\tinyexpr.h>
#include <D:\ ... \Mywork\Cpp\Starter\tinyexpr.c>

int main()
{
std::cout << "Input arithmetic calculation: \n";
std::string calc;
std::cin >> calc;
double result = te_interp(calc.c_str(), 0);
std::cout << "Result = ";
std::cout << result << '\n';
return 0;
}

How are you compiling?

@EvilPudding Using Dev-C++ 5.11 with TDM GCC 4.9.2 64-bit
Compiler error;
D:\EvaxHybrid\Mywork\Cpp\Starter\tinyexpr.c: In function 'void pn(const te_expr*, int)':
D:\EvaxHybrid\Mywork\Cpp\Starter\tinyexpr.c:644:32: error: invalid conversion from 'void*' to 'const te_expr*' [-fpermissive]
pn(n->parameters[i], depth + 1);
^
D:\EvaxHybrid\Mywork\Cpp\Starter\tinyexpr.c:625:13: note: initializing argument 1 of 'void pn(const te_expr*, int)'
static void pn (const te_expr *n, int depth) {
^

This line is your problem:

#include <D:\ ... \Mywork\Cpp\Starter\tinyexpr.c>

You need to remove that line! Then add tinyexpr.c to your project in your IDE. Your IDE should compile it separately as C code, and then link it in after.

As stated previously, your error comes from you compiling tinyexpr.c as C++, when it is in fact C code.

You should find a tutorial about how C and C++ compilers work. To be productive with programming, you need to not only know the programming language, but you need to understand how your tools work as well.

@codeplea Ok, I will try it tonight.