开发者

Porting C code to C#

As a part of my work, I have to port parts of firmware written in c to a gui software that is written in c#. So, I have to convert the c code to c#. I could have used the c code as it is and call it from the gui, but people in here decided to port instead of using c file as it is.

When I was going to through the code, I found something like this:

static xdata x y;

Then开发者_开发百科 after some research found that xdata says the chip to store this variable in a external memory. Now the problem is how can I write that line in c#.

Thanks everyone and this wonderful community.


Just remove it. xdata just a tip for the compiler to where to store the variable. If you remove it the C# compiler will figure it out on it own.


Consider porting your C code to a .NET C++ dll instead of C#. This should minimize your porting problems. The xdata keyword can be effectively remove by an empty macro.

Use something like the following in a header file in your C++ project:

#define xdata

The .NET C++ dll can easily be referenced by the C# GUI project.


Your question leaves out a lot of details. When I see "I have to port parts of firmware written in c to a gui software that is written in c#.", I would assume the "parts" being ported are not hardware related. However, maybe that is not the case and you are using something like the .NET Micro Framework. Are you going to be running the C# code on some form of embedded CLR, or is strictly going to run on a PC? If it's just going to run on a full Windows .NET platform. If the latter then you can ignore the xdata qualifier since C# has no analog to it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜