The quickjs.h can't be included in a c++ compilation unit, can it? #538
Replies: 2 comments 5 replies
-
Hi Please-just-dont, I have put your question text to the [ Code: Java, C/C++ } GPT engine. This the answer that I got: ============== The issue you're encountering stems from the fact that QuickJS uses designated initializers and compound literals, which are features available in C99 but not in C++. In C99, you can initialize structures using a syntax like this:
However, C++ does not support this syntax in the same way, which is why you're running into the error: Solution What the Macro Looks Like in C
This syntax is allowed in C but not in C++. Fix: Convert C-style Compound Literals to C++-style Initialization
Steps to Fix:
This avoids the C99-specific syntax that causes the issue, and will compile in both C and C++. Summary of Key Changes
Additional Suggestions: ============== I hope that this is helpful to follow up on this issue and solve it. Best, |
Beta Was this translation helpful? Give feedback.
-
@saghul Hi, this is pretty much the latest version I tested, it was from like 7 days ago, doesn't compile in C++ for the reason given, it's using compound literals in the header and therefore can't be included into c++ |
Beta Was this translation helpful? Give feedback.
-
It looks like this Javascript interpreter was written in a style of C that isn't compatible with C++ and thus won't compile. JS_MKVAL macro is underlined:
static js_force_inline JSValue JS_NewBool(JSContext *ctx, JS_BOOL val)
{
return JS_MKVAL(JS_TAG_BOOL, (val != 0));
}
Error C4576 a parenthesized type followed by an initializer list is a non-standard explicit type conversion syntax
I looked at the macro, I'm pretty sure I ran into this problem before and I'm pretty sure it has something to do with a C feature, can't remember what it's called anymore, and I couldn't find it from a Google search, but it looks like this (MyType) { .member1 = 2, .member2 = 3 } . That gnarly looking cast thingy before the initialisation, it's a newer C feature that won't compile in C++.
Beta Was this translation helpful? Give feedback.
All reactions