I have gone through all other similar issues, and yet I cannot understand why I am getting this error :
warning: suggest parentheses around arithmetic in operand of '|' [-Wparentheses]
&((~((PERIPHS_IO_MUX_FUNC)<<(PERIPHS_IO_MUX_FUNC_S)))) \
I am using xtensa-gcc. Following is the code (from ESP8266 SDK) :
#define PIN_FUNC_SELECT(PIN_NAME, FUNC) do { \
WRITE_PERI_REG(PIN_NAME, \
(READ_PERI_REG(PIN_NAME)) \
&((~((PERIPHS_IO_MUX_FUNC)<<(PERIPHS_IO_MUX_FUNC_S)))) \
|((((FUNC&BIT2)<<(2))|(FUNC&0x3))<<(PERIPHS_IO_MUX_FUNC_S)) ); \
} while (0)
The "&" and "|" leading on the last two lines both are at the same level of parentheses. The compiler is warning you that there can be some confusion by developers regarding precedence.
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)
I was working with a old codebase where I encountered few line of code which was causing lot of repeated warnings during compilation.
#define EXAMPLE(_ptr) \
{ \
register uintptr_t *__sp __asm__("sp"); \
(_ptr[0]) = (uintptr_t) __sp; \
asm volatile("sw $a0,%0" : "=m" (_ptr[1])); \
//SOME OTHER CODE HERE
}
the warning was:
warning: ‘__sp’ may be used uninitialized in this function
Can anyone help me in understanding what is happening in this code block and how to remove this warning.
I have written a macros but when i use the code i get expected identifier error.
Below is my macros
#define ITK(arguments) \
{ \
int iFail=0; \
iFail = arguments; \
if(iFail != ITK_ok) \
{ \
char* s; \
TC_write_syslog("Following Method Retruns error "#arguments "\n");\
TC_write_syslog("Error is in the line [%d] of the file ["__FILE__"]\n",[__LINE__]);\
EMH_ask_error_text(iFail,&s);\
TC_write_syslog("And the error is [%s]",s);\
if(s!=0) MEM_FREE(s);\
} \
}
As Davis Herring said the reason is your [__LINE__]
When you are lost and you do not see where is the error on that kind of case look at the code after the pre processing, for instance using g++ do g++ -E < other flags except -c > -o temp.cc and if you still don't see in temp.cc add line breaks in the interesting portion of code in temp.cc then compile temp.cc to look at compiler errors/warnings
Looks like a simple typo to me. You need to remove [ and ] here:
TC_write_syslog("Error is in the line [%d] of the file ["__FILE__"]\n",[__LINE__]);
// ^ ^
Note that instead of using printf's %d to insert __LINE__ into a string at runtime, you can convert __LINE__ to a string literal at compile-time:
#define STR(x) STR_(x)
#define STR_(x) #x
TC_write_syslog("Error is in the line " STR(__LINE__) " of the file ["__FILE__"]\n");
I have started working with Neural Networks, so I got a FANN library (http://leenissen.dk/fann/wp/). I am having problems to compile it, specifically file
/fann-master/src/fann_io.c
where I am receiving a error on line 346:
fann_io.c:346:29: error: unable to find string literal operator ‘operator""type’ with ‘const char [20]’, ‘long unsigned int’ arguments
if(fscanf(conf, name"="type"\n", val) != 1) \
And I have looked it up, but I still have no idea how to fix it. Here is the function.
#define fann_scanf(type, name, val) \
{ \
if(fscanf(conf, name"="type"\n", val) != 1) \
{ \
fann_error(NULL, FANN_E_CANT_READ_CONFIG, name, configuration_file); \
fann_destroy(ann); \
return NULL; \
} \
}
The solution which helped me was to use compiler option
-std=c++03
So in the end I could compile the whole project by typing in
g++ main.cpp -std=c++03
I copied a Big Int Library into my code and I'm having random errors in one of the classes. (The code is older)
One of my errors is in a define statement, not really sure how these work.
Everything under "tmpthis;" is giving an error.
#define DTRT_ALIASED(cond, op) \
if (cond) {\
BigUnsigned tmpThis;
tmpThis.op; //Error: no storage class or type specifier
*this = tmpThis; //Error: *this expected an identifier Error: No suitable conversion from "BigUnsigned" to "int" exists.
return; // Error: expected a declaration
} \
On top of that there are a few random if and for statements with the error "expected a declaration" and some variables with the error " no storage class or type specifier"
NOTE: these random errors also had instances where they were not errors also, it was inconsistent.
A bare-bones fix to the macro is:
#define DTRT_ALIASED(cond, op) \
if (cond) { \
BigUnsigned tmpThis; \
tmpThis.op; \
*this = tmpThis; \
return; \
}
This stands a chance of compiling when used in a function that doesn't return a value, if the reference to op in tmpThis.op makes sense to the compiler. It is somewhat peculiar (and limited) code, but there might be a use for it.