Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid conversion compiler warnings #61

Closed
kornkaobat opened this issue Jan 5, 2020 · 8 comments
Closed

Invalid conversion compiler warnings #61

kornkaobat opened this issue Jan 5, 2020 · 8 comments

Comments

@kornkaobat
Copy link

kornkaobat commented Jan 5, 2020

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;
}
@codeplea
Copy link
Owner

codeplea commented Jan 5, 2020

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

@codeplea
Copy link
Owner

codeplea commented Jan 5, 2020

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);

@kornkaobat
Copy link
Author

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

@kornkaobat
Copy link
Author

kornkaobat commented Jan 5, 2020

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;
}

@EvilPudding
Copy link
Contributor

How are you compiling?

@kornkaobat
Copy link
Author

@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) {
^

@codeplea
Copy link
Owner

codeplea commented Jan 5, 2020

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.

@kornkaobat
Copy link
Author

@codeplea Ok, I will try it tonight.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants