i have problem to set in to c++ MACRO singletone function result .
this is what i have :
the macro
#define CCDICT_FOREACH(__dict__, __el__) \
CCDictElement* pTmp##__dict__##__el__ = NULL; \
if (__dict__) \
HASH_ITER(hh, (__dict__)->m_pElements, __el__, pTmp##__dict__##__el__)
and this is how i try to set it :
CCDictElement* pElement = NULL;
CCDICT_FOREACH(GameSingleTone::getInstance()->getGemsDictionary(), pElement)
{
}
the method getGemsDictionary() returns me:
CCDictionary*,gemsDictionary;
the compilation error im getting is (on the line of the MACRO):
error C2143: syntax error : missing ';' before '{'
but if i do :
CCDictionary* tempDictionary = CCDictionary::create();
tempDictionary = GameSingleTone::getInstance()->getGemsDictionary();
CCDICT_FOREACH(tempDictionary , pElement)
{
}
every thing is working .
why ?
Macros simply do text replacement. So when you do this:
CCDICT_FOREACH(GameSingleTone::getInstance()->getGemsDictionary(), pElement)
This line:
CCDictElement* pTmp##__dict__##__el__ = NULL; \
becomes this:
CCDictElement* pTmpGameSingleTone::getInstance()->getGemsDictionary()pElement = NULL;
Which is utter nonsense. This, on the other hand:
CCDICT_FOREACH(tempDictionary , pElement)
translates to this:
CCDictElement* pTmptempDictionarypElement = NULL;
Which is perfectly okay.
Related
i have code. but I can not understand why he swears?
This is line 17
if (!empty($city_result = $this->model_module_novapochta->getCity($this->request->post['novaposhta_key']))) {
**Parse error: syntax error, unexpected '=', expecting ')' in /home/s2332/***.com/www/admin/controller/shipping/novaposhta.php on line 17**
if (!empty($this->request->post['refresh']) && !empty($this->request->post['novaposhta_key'])) {
if (!empty($city_result = $this->model_module_novapochta->getCity($this->request->post['novaposhta_key']))) {
$this->session->data['error'] = $city_result;
} elseif (!empty($address_result = $this->model_module_novapochta->getAdress($this->request->post['novaposhta_key']))) {
$this->session->data['error'] = $address_result;
}
};
Your if statement is wrong...
You have write:
if (!empty($city_result = $this->model_module_novapochta->getCity($this->request->post['novaposhta_key']))) {
must be:
$city_result = $this->model_module_novapochta->getCity($this->request->post['novaposhta_key']);
if (!empty($city_result)) {
//your code here
I was trying to convert 32bit game client to 64bit. But I can't compile, because the client has an inline ASM code, 64bit doesn't support __asm inline. So I can't find a solution for this. I hope I can get into this community.
define inline code:
#define PR_FLOAT_TO_INTASM __asm \
{ \
__asm fld PR_FCNV \
__asm fistp PR_ICNV \
}
#define PR_FLOAT_TO_INT(inreal, outint) \
{ \
PR_FCNV = (inreal); \
PR_FLOAT_TO_INTASM; \
(outint) = PR_ICNV > PR_FCNV ? PR_ICNV - 1 : PR_ICNV; \
}
Example code using:
float CMapOutdoor::GetTerrainHeight(float fx, float fy)
{
if (fy < 0)
fy = -fy;
long lx, ly;
PR_FLOAT_TO_INT(fx, lx);
PR_FLOAT_TO_INT(fy, ly);
WORD usCoordX, usCoordY;
usCoordX = (WORD)(lx / CTerrainImpl::TERRAIN_XSIZE);
usCoordY = (WORD)(ly / CTerrainImpl::TERRAIN_YSIZE);
BYTE byTerrainNum;
if (!GetTerrainNumFromCoord(usCoordX, usCoordY, &byTerrainNum))
return 0.0f;
CTerrain* pTerrain;
if (!GetTerrainPointer(byTerrainNum, &pTerrain))
return 0.0f;
return pTerrain->GetHeight(lx, ly);
}
Error code:
error C2146: syntax error : missing ';' before identifier 'PR_ICNV'
error C2146: syntax error : missing ';' before identifier 'fistp'
error C2146: syntax error : missing ';' before identifier '}'
#define A2W_EX(lpa, nChars) (\
((_lpa_ex = lpa) == NULL) ? NULL : (\
_convert_ex = (lstrlenA(_lpa_ex)+1),\
FAILED(::ATL::AtlMultiply(&_convert_ex, _convert_ex, static_cast<int>(sizeof(WCHAR)))) ? NULL : \
ATLA2WHELPER( \
(LPWSTR)_ATL_SAFE_ALLOCA(_convert_ex, _ATL_SAFE_ALLOCA_DEF_THRESHOLD), \
_lpa_ex, \
_convert_ex / sizeof(WCHAR), \
_acp_ex)))
I am copy-pasting some macros from Visual Studio int MingW and I am getting the following error
In member function 'ATL::CComVariant& ATL::CComVariant::operator=(LPCSTR)':
C:\.../atlconv.h:635:11: error: expected primary-expression before ')' token
(LPWSTR)_ATL_SAFE_ALLOCA(_convert_ex, _ATL_SAFE_ALLOCA_DEF_THRESHOLD), \
^
Any suggestions on how to fix this issue ?
In order to collect memory leak on my debug tree I've added:
#ifdef _DEBUG
#define new DEBUG_NEW
#endif
But I get a compilation error on the last line of:
void* AA::rpyCreateObject(void* addrs)
{
if (addrs == NULL)
return new AA;
else
return new(addrs) AA; // error C2061: syntax error : identifier 'addrs'
}
What I want this code to do is: the first new is DEBUG_NEW, and the second is the regular new.
Note - I CAN NOT use #undef new as this function is actually a macro:
#define ObjGenMacro(ClsName) void* ClsName::rpyCreateObject(void* addrs) { \
if (addrs == NULL) \
return new ClsName; \
else \
return new(addrs) ClsName; \
}
How can this be done?
I have an AVOption structure:
static const AVOption options[] = {
COMMON_OPTIONS // error here
{ NULL }
};
and COMMON_OPTIONS is defined as:
#define COMMON_OPTIONS \
{ "interp", "select interpolation mode", OFFSET(interpolation), AV_OPT_TYPE_INT, {.i64=INTERPOLATE_TETRAHEDRAL}, 0, NB_INTERP_MODE-1, FLAGS, "interp_mode" }, \
{NULL}
I am getting an error:
2>c:\users\awki6\desktop\ffmpeg\libavfilter\vsrc_testsrc.cpp(98): error C2143: syntax error : missing '}' before '.'
Your COMMON_OPTIONS macro has already the { NULL } and does not ends with a ,, so:
static const AVOption options[] = {
COMMON_OPTIONS
};
will solve your problem.
Past answer before the edit:
Even if we don't know what does COMMON_OPTIONS expand to, I guess that you just miss the comma after it:
static const AVOption options[] = {
COMMON_OPTIONS,
// ^
{ NULL }
};