Game Development Community

C# blackmagic.. or the missery of a C++ programer

by Casey Weidner · in Technical Issues · 09/01/2006 (9:24 pm) · 4 replies

Hi every one.. im hoping that some GURU of the C# magic system can tell me how to properly port c/c++ code using #define directives over to C#.. im not sure how to go about it as the defines really dont have a specific data type.. one example is :

#define PCL pc.b.l

what would be the best way to translate that to C#


thanks
Casey

#1
09/02/2006 (8:02 am)
I don't think you can, though I'm far from a C# guru.

With #define in C#, you can only have things like: #define PCL

#define PCL pc.b.l won't work. I think you can only define a symbol and then use other preprocessor commands like #ifdef. I don't think you can #define something to something else and expect it to work. C# doesn't have a preprocessor phase - it just includes some "preprocessor" directives for use during the lex phase.

Define a method getPCL() that returns pc.b.l. The Just-In-Time compiler will probably inline small methods like that if they get called alot, so performance shouldn't suffer.

See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/csref/html/vclrfdefine.asp .
#2
09/02/2006 (1:27 pm)
Hrm..ok.. i wouldnt have ever thought of doing a function like that... so basicly i want to make a class for all my defines and just make a get***() metiod for all my defines.. and change out all of the instances of the define with a method call.... doesnt sound too scary

Thanks for the tips
#3
09/02/2006 (1:37 pm)
Look into properties. You don't generally need to use accessors in C# in the C++ sense of accessors.
#4
09/03/2006 (6:51 pm)
Thanks Tom i've looked into the properties you mentioned.. a very neat addition if i do say so.. great for read only variables..

most of the problems im having is the fact that the code im porting is not my own.. and there are lots of custom data types emulating this processor.. so its just taking time to wade threw it all and deciding how to assign all the defines to int or byte or what not.. should be interesting when im finaly done though.. if it works