I have the following macro:
#define FIELD_ACCESSOR_FUNCTIONS(typeName, fieldAccessorNamePrefix) \
JNIEXPORT jobject JNICALL my_pckg_NativeExecutor_get ## typeName ## FieldValue(JNIEnv* jNIEnv, jobject nativeExecutorInstance, jobject target, jobject field) { \
return environment-> ## fieldAccessorNamePrefix ## FieldAccessor->getValue(jNIEnv, target, field); \
}
FIELD_ACCESSOR_FUNCTIONS(Object, object)
And when I start the compilation I get the following error:
NativeExecutor.cpp:59:20: error: pasting "->" and "object" does not give a valid preprocessing token
return environment-> ## fieldAccessorNamePrefix ## FieldAccessor->getValue(jNIEnv, target, field); \
^~
How can I solve?
Drop the first ##. The name you are trying to generate is fieldAccessorNamePrefix ## FieldAccessor. The -> must not be part of the token.
Related
Trying to simplify writing boiler plate, but I get Field cannot have type 'void' and / or Expected ')'
Newbie c++, I've seen a bunch questions like this, but still can't figure it out. The errors are still too cryptic to me to able to google them..
#define GAME_STAT(Stat) \
UPROPERTY(BlueprintReadOnly, Category = "Stats", ReplicatedUsing = OnRep_##Stat##) \
FGameplayAttributeData ##Stat##; \
GAME_STAT_ACCESS(UGameStats, ##Stat##); \
UFUNCTION() \
virtual void OnRep_##Stat##(const FGameplayAttributeData& Old##Stat##);
GAME_STAT("Health")
I want to generate the code with word "Health" instead of stand-in "Stat"
Thanks!
## is for pasting tokens together, but it looks like you think it is "reverse stringification".
It's also a binary operator, not an "around-ary" operator.
That is,
#define hello(x) Hello_##x
hello(World)
will produce
Hello_World
This should work (but is thoroughly untested):
#define GAME_STAT(Stat) \
UPROPERTY(BlueprintReadOnly, Category = "Stats", ReplicatedUsing = OnRep_##Stat) \
FGameplayAttributeData Stat; \
GAME_STAT_ACCESS(UGameStats, Stat); \
UFUNCTION() \
virtual void OnRep_##Stat(const FGameplayAttributeData& Old##Stat);
GAME_STAT(Health)
OS:macOS 10.13.3
IDE:Android studio 1.5.1
g++:4.2.1
scene:
I wanna develop with NDK using c++.When I define a c++ class to build,the Gradle Console return an error like below:
> src/main/jni/addcomputer.c:23:12: error: expected ';' after top level declarator
jclass Test{
^
;
1 error generated.
make: *** [build/intermediates/ndk/obj/local/arm64-v8a/objs/addcomputer/addcomputer.o] Error 1
:app:ndkBuild FAILED
and my .cpp like below:
#include "com_BTC_ui_JNI.h"
//......
JNIEXPORT jstring JNICALL
Java_com_BTC_ui_JNI_getString(JNIEnv *env, jobject instance)
{
return (*env)->NewStringUTF(env, "mytest-sample-x");
}
JNIEXPORT jint JNICALL
Java_com_BTC_ui_JNI_plus(JNIEnv *env, jobject instance, jint a, jint b)
{
return a+b;
}
jclass Test{//this is where the error occur
private:
jint mytest;
};
When I open a terminal to build a .cpp file which contain a class define,it return a same error.I cannot find the reason.Anyone can help me?
The error has gone , I just fixed some basic problem.Although the compile process is ok, the running time has occur another error of cannot find implementation of native method.I guess that's caused by compiler.Now I should close this question.Thanks all for focusing this question.
I have the following c++ code:
#define MATH_FASTCALL(name, fname) \
static int math_ ## name ## _precall (lua_State *L, StkId func, int nresults) { \
StkId arg1 = func + 1; \
llvm_arg_tonumber(L, arg1, 1); \
setnvalue(func, fname(nvalue(arg1))); \
L->ci--; \
L->top = func + 1; \
L->base = L->ci->base; \
return PCRC; \
fallback: \
return luaD_precall_c(L, func, nresults); \
}
MATH_FASTCALL(abs, fabs)
When I try to compile it in Visual Studio 14 2015 it gives an error at the line with MATH_FASTCALL:
expression must be a pointer to a complete object type
What could be the problem with this code?
The error message makes it sound like the macro is dereferencing a pointer to an incomplete type. Make sure that lua_State and the type of lua_State::ci are defined (not just declared) before invoking the macro.
I'm trying to build the following code in Eclipse CDT on Linux with GNU:
log_defs.h
#pragma once
#define dbg_log(fmt, ...) debug_logger::debug(__FILE__, __FUNCTION__, __LINE__, fmt, __VA_ARGS__, 0)
ErrorMessage.cpp
ErrorMessage::ErrorMessage( void ){ dbg_log( L"ErrorMessage::ErrorMessage _in" ); }
ErrorMessage::~ErrorMessage( void ){ dbg_log( L"ErrorMessage::~ErrorMessage _in" ); }
I'm getting the following errors:
../sources/ErrorMessage.cpp: In constructor ‘ErrorMessage::ErrorMessage()’:
/include/log_defs.h:27:97: error: expected primary-expression before ‘,’ token
#define dbg_log(fmt, ...) debug_logger::debug(__FILE__, __FUNCTION__, __LINE__, fmt, __VA_ARGS__, 0)
^
../sources/ErrorMessage.cpp:150:37: note: in expansion of macro ‘dbg_log’
ErrorMessage::ErrorMessage( void ){ dbg_log( L"ErrorMessage::ErrorMessage _in" ); }
^
../sources/ErrorMessage.cpp: In destructor ‘ErrorMessage::~ErrorMessage()’:
/include/log_defs.h:27:97: error: expected primary-expression before ‘,’ token
#define dbg_log(fmt, ...) debug_logger::debug(__FILE__, __FUNCTION__, __LINE__, fmt, __VA_ARGS__, 0)
^
../sources/ErrorMessage.cpp:152:38: note: in expansion of macro ‘dbg_log’
ErrorMessage::~ErrorMessage( void ){ dbg_log( L"ErrorMessage::~ErrorMessage _in" ); }
The reason is that when you don't pass any additional arguments to the macro, __VA_ARGS__ expands to nothing. You therefore end up with the following code like this after macro expansion:
debug_logger::debug("SomeFile", "SomeFunction", 42, L"TheFormatString", , 0)
If the code you've posted faithfully captures your real scenario, the way out is easy: subsume fmt into the variadic part:
#define dbg_log(...) debug_logger::debug(__FILE__, __FUNCTION__, __LINE__, __VA_ARGS__, 0)
That way, you'll always pass at least one argument (the fmt string) to the macro, and the commas will work out nicely.
I have a library with several macros, it compiles fine on AIX, but now i need to compile the same code and it seems the macros stopped to work.
I keep receiving the message:
error: pasting "::" and "EVENT_DATA" does not give a valid preprocessing token.
Is there a way to make the c++ preprocessor on linux acts like on aix.
I'm using g++ on linux and xlc_r on AIX.
Here is one of the macros.
#define E_TRA_INMOD(MName, Comp) \
static const ES_TracMg::ES_TracComps ES_TracComp = \
ES_TracMg::##Comp; \
static char* ES_Mod_Namp = MName; \
static unsigned long ES_SerMas = \
ES_TracMg::m_MServ[ES_TracMg##Comp];
I call it like E_TRA_INMOD("Error", EVENT_DATA);
The error is:
error: pasting "::" and "EVENT_DATA" does not give a valid preprocessing token.
I think you don't want to use ## here:
#define E_TRA_INMOD(MName, Comp) \
static const ES_TracMg::ES_TracComps ES_TracComp = \
ES_TracMg::##Comp; \
It should be
#define E_TRA_INMOD(MName, Comp) \
static const ES_TracMg::ES_TracComps ES_TracComp = \
ES_TracMg::Comp; \
You don't have two tokens to glue together into a single token, you just have whatever Comp expands to.
What are you trying to do in the macro? It looks like the first token paste is redundant:
#define E_TRA_INMOD(MName,Comp) \
static const ES_TracMg::ES_TracComps ES_TracComp = \
ES_TracMg::Comp; \
static char* ES_Mod_Namp = MName; \
static unsigned long ES_SerMas = \
ES_TracMg::m_MServ[ES_TracMg##Comp];