-
August 26th, 2010, 12:18 PM
#1
[RESOLVED] Problem with macros for creating get/set functions
"error C2084: function 'D3DXVECTOR3 FName(int)' already has a body"
I am using Visual Studio 2005 professional.
I don't understand why FName (function name) is taken directly as the function name instead of being replaced with the macro argument.
Code:
// Actual syntax
#define Get_InsProp3(FName,PName,PPart1,PPart2,PPart3,DType,DefVal) inline DType FName (int Instance) { Object_Instance* pInstance; if (GameEngine_Object_Instance_IsValid(Instance)) { pInstance = (Object_Instance*)Instance; return DType(pInstance->##PName##.##PPart1, pInstance->PName##.##PPart2, pInstance->PName##.##PPart3); } else { ReportBadReference_Instance(L#FName, Instance); return DType##DefVal; } };ReportBadReference_Instance(L#FName, Instance); return DefVal; } };
// Simplified with multiple lines
#define Get_InsProp3(FName,PName,PPart1,PPart2,PPart3,DType,DefVal)
inline DType FName (int Instance) {
Object_Instance* pInstance;
if (GameEngine_Object_Instance_IsValid(Instance)) {
pInstance = (Object_Instance*)Instance;
return DType(pInstance->##PName##.##PPart1, pInstance->PName##.##PPart2, pInstance->PName##.##PPart3);
} else {
ReportBadReference_Instance(L#FName, Instance); return DType##DefVal;
}
};
Last edited by Dawoodoz; August 26th, 2010 at 01:27 PM.
Reason: Code tags
-
August 26th, 2010, 12:57 PM
#2
Re: Problem with macros for creating get/set functions
Please, look at your post and, please, tell us: can you read/understand this macro definition? 
I can't. 
Please, edit your post adding Code tags and indentations.
Victor Nijegorodov
-
August 26th, 2010, 01:20 PM
#3
Re: Problem with macros for creating get/set functions
Last edited by Dawoodoz; August 26th, 2010 at 01:28 PM.
Reason: I have figured out how to use it.
-
August 26th, 2010, 01:37 PM
#4
Re: Problem with macros for creating get/set functions
No. The second line is toooooooooo long.
Victor Nijegorodov
-
August 26th, 2010, 01:40 PM
#5
Re: Problem with macros for creating get/set functions
The second line is the same code as below. Just ignore it if you can't read it.
-
August 26th, 2010, 02:52 PM
#6
Re: Problem with macros for creating get/set functions
I tested the second variant (with \ added) in VS2005 and it worked like a charm.
Have you tried setting your compiler to pre-process to file?
-
August 26th, 2010, 03:40 PM
#7
Re: Problem with macros for creating get/set functions
Pre processing to file gave a lot of empty lines but could be useful for debugging if I know what to search for.
This seems to do the same thing but with the same error.
Code:
#define Get_InsProp3(FName,PName,PPart1,PPart2,PPart3,DType,DefVal)\
inline DType FName (int Instance) {\
Object_Instance* pInstance;\
if (GameEngine_Object_Instance_IsValid(Instance)) {\
pInstance = (Object_Instance*)Instance;\
return DType(pInstance->PName##.##PPart1, pInstance->PName##.##PPart2, pInstance->PName##.##PPart3);\
} else {\
ReportBadReference_Instance(L#FName, Instance);\
return DType##DefVal;\
}\
};
I need something to use with FName to make the precompiler see that it is an argument and not a string.
-
August 26th, 2010, 04:19 PM
#8
Re: Problem with macros for creating get/set functions
What, exactly, are you trying to do? Create a macro that creates a function "on the fly"? If so, why not try re-writing the function as a template?
Viggy
-
August 26th, 2010, 04:20 PM
#9
Re: Problem with macros for creating get/set functions
 Originally Posted by Dawoodoz
Pre processing to file gave a lot of empty lines but could be useful for debugging if I know what to search for.
The idea is, you turn on the 'send preprocessor output to file' option (or whatever it's called), then you can see (instead of wonder or guess) exactly what your '#define Get_InsProp3' macro is expanding to.
If you already did this & still have questions, then post what it expanded to here.
-
August 26th, 2010, 04:33 PM
#10
Re: Problem with macros for creating get/set functions
 Originally Posted by MrViggy
What, exactly, are you trying to do? Create a macro that creates a function "on the fly"? If so, why not try re-writing the function as a template?
Viggy
I have a lot of get and set functions for my graphics engine and need macros for generating the functions.
This is how one of the final get set interfaces should be in the end.
Code:
D3DXVECTOR3 GameEngine_Object_Instance_GetPosition(int Instance) {
Object_Instance* pInstance;
if (GameEngine_Object_Instance_IsValid(Instance)) { pInstance = (Object_Instance*)Instance;
return D3DXVECTOR3(pInstance->transformation._41, pInstance->transformation._42, pInstance->transformation._43);
} else {
ReportBadReference_Instance(L"GameEngine_Object_Instance_GetPosition", Instance);
return D3DXVECTOR3(0.0f, 0.0f, 0.0f);
}
}
void GameEngine_Object_Instance_SetPosition(int Instance, D3DXVECTOR3 NewPosition) {
Object_Instance* pInstance;
if (GameEngine_Object_Instance_IsValid(Instance)) { pInstance = (Object_Instance*)Instance;
pInstance->transformation._41 = NewPosition.x;
pInstance->transformation._42 = NewPosition.y;
pInstance->transformation._43 = NewPosition.z;
} else {
ReportBadReference_Instance(L"GameEngine_Object_Instance_SetPosition", Instance);
}
}
-
August 27th, 2010, 06:52 AM
#11
Re: Problem with macros for creating get/set functions
Of what I understand about function templates, they can only be used for taking multiple datatypes for one function name.
-
August 27th, 2010, 07:21 AM
#12
Re: Problem with macros for creating get/set functions
I have found the error. It was a side effect of another macro so that other macros crashed.
Last edited by Dawoodoz; August 27th, 2010 at 08:40 AM.
Reason: Found the bug
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|