C# 到 C++翻译

发布于 2024-10-01 12:02:03 字数 1431 浏览 4 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

柠栀 2024-10-08 12:02:03

不。这是行不通的。

C# 有一个垃圾收集器。 C 和 C++ 则不然。您将不得不重新考虑如何在 C++ 中分配和释放对象。

由于您已经完成了该项目,因此用 C/C++ 重写它可能会非常容易。你已经明白了这个问题,并且已经表达过一次了。

Don't. This will not work.

C# has a garbage collector. C and C++ don't. You will have to rethink how you allocate objects and release them in C++.

Chances are, since you already have completed the project, rewriting it in C/C++ will be quite easy. You already understand the problem and have expressed it once before.

-柠檬树下少年和吉他 2024-10-08 12:02:03

从 C# 到 C++ 不存在一对一的映射。较低级别的编程模型和平台有很大不同。以内存管理为例。

最好的机会是重写您的应用程序或尝试获取 .NET Compact Framework.NET Micro Framework 在硬件中运行。

编辑:
请注意,如果您的硬件不受支持,至少 .NET Micro Framework 有一个移植工具包。

There is no 1 to 1 mapping from c# to c++. The programming model and platforms are very different at the lower levels. Take memory management for example.

Your best chance is either to rewrite your application or try to get .NET Compact Framework or .NET Micro Framework to run in the hardware.

Edit:
Note that at least the .NET Micro Framework has a porting kit if your hardware is not supported.

飞烟轻若梦 2024-10-08 12:02:03

由于设计是应用程序开发中成功的一半,因此您的C#原型应该可以很好地为您服务,但您不太可能找到合适的自动翻译工具。如果您没有大量使用 .NET 类库,尤其是那些与底层操作系统 API 相关的部分,那么 C# 应该可以轻松地手动转换为 C++。代码体语法和语义非常相似;更不同的是封闭的结构元素,例如类定义。

所需的工作量取决于应用程序代码的大小,但其中大部分是机械性的。最大的区别是,您需要更加小心 C++ 中的内存管理,因为没有自动垃圾回收。

Since design is half the battle in application development, your C# prototype should serve you well, but you are unlikely to find a suitable automatic translation tool. If you have not made heavy use of the .NET class library, especially those parts that relate to the underlying OS API, C# should be easily manually translated to C++. The code body syntax and semantics are very similar; it is the enclosing structural elements such as class definitions that are more different.

The required effort depends on the size of the application code, but much of that is mechanistic. The biggest difference being that you need to be more careful with memory management in C++ since there is no automatic garbage collection.

美人如玉 2024-10-08 12:02:03

学习 C 或 C++。没有其他选择。

这两种语言与 C# 和 .NET 截然不同,并且无法自动转换。 (如果是的话,它肯定不会让您“弄清楚运行它所需的大部分内容”。这将是完全无法识别的代码,无法读取或扩展。)

为了编写一个有效的 C 或 C++ 程序,需要由 C 或 C++ 程序员编写代码。好消息是它并不一定那么困难。您不必学习 C++ 语言的每个角落。但您确实需要学习基础知识。

如果您正在寻找一种快速而肮脏的方式来起步,学习 C 可能是一个更好的选择,因为这种语言更小、更简单。但 C++ 也是可行的。只是不要认为阅读 15 分钟的在线教程就可以逃脱惩罚。

Learn C or C++. There are no alternatives.

Both languages are radically different from C# and .NET, and automatic conversion is not possible. (and if it were, it certainly wouldn't allow you to "figure out most of what is required to make it run". It would be completely unrecognizable code, that'd be impossible to read or extend.)

In order to write a working C or C++ program, a C or C++ programmer needs to write the code. The good news is that it doesn't have to be that difficult. You don't have to learn every corner of the C++ language. But you do need to learn the basics.

If you're looking for the quick and dirty way to get off the ground, learning C might be a better option, because the language is so much smaller and simpler. But C++ is doable too. Just don't think you can get away with reading a 15-minute online tutorial.

彼岸花ソ最美的依靠 2024-10-08 12:02:03

没有翻译人员。

.NET Micro Framework 已移植到 Phycore LPC3180 (NXP) 平台与您的主板没有什么不同,因此可以完成,但您仍然需要移植.NET 框架到您的平台。
除非您要移植 Meamo,否则您不太可能使用 Mono AOT到您的 mbed 板。
任何移植都要求您能够编写 C 代码。

最好、最快的方法是学习 C++。
一旦您开始使用 C++ 并理解这些差异,C++ 和 C# 之间的差异就不会太大。您还必须使用 mbed 库来进行硬件控制和通信,而不是 C# 提供的库。

C# 代码是调试程序设计的良好原型,但它不会帮助您实现目标。现在您已经了解了这个问题,应该不会太难。

There are no translators.

The .NET Micro Framework has been ported to a Phycore LPC3180 (NXP) platform that is not to dissimilar to your board so it can be done but you still need to port the .NET framwork to your platform.
It is unlikely that you will be able to use Mono AOT unless you are going to port Meamo to to your mbed board.
Any porting would require you to be able to program C code.

The best and fastest way forward would be for You to learn C++.
The differences between C++ and C# are not to big once you get going with C++ and understand the differences. You also going to have to use the mbed library for your hardware control and communications instead of what is provided by C#.

The C# code was a good prototype to debug your program design but it is not going to help you on the target. Now that you understand the problem it should not be to hard.

叫嚣ゝ 2024-10-08 12:02:03

我不确定您是如何做到这一点而没有意识到目标平台无法运行 .NET,但如果 Mono 的 Ahead-of-Time 编译器能够输出到您的目标平台。

至少这样你就不会扔掉(几个月的?)代码。

I'm not sure how you got this far without realising that the target platform couldn't run .NET, but it might be worth seeing if Mono's Ahead-of-Time compiler is able to output to your target platform.

At least then you wouldn't be throwing out (months of?) code.

岁月苍老的讽刺 2024-10-08 12:02:03

由于您使用垃圾收集语言编写应用程序,因此将其移植到 mbed 平台的最快方法应该是将应用程序移植到在 mbed 上运行的垃圾收集语言。

我还没有尝试过,但 eLua 应该有一个在 mbed 平台上运行的初步端口,并且 Lua 相当容易学习。
http://mbed.org/users/jsnyder/notebook/elua-preliminary- port/

如果你能让你爸爸在 mbed 平台上启动 eLua,我怀疑与尝试将你的应用程序转换为 C++ 相比,你可以相当容易地完成转换。

Since you wrote the application in a garbarge-collected language, the fastest way to port this to an mbed platform should be to port the application to a garbage-collected language which runs on mbed.

I haven't tried it, but eLua is supposed to have a preliminary port which runs on the mbed platform, and Lua is fairly simple to learn.
http://mbed.org/users/jsnyder/notebook/elua-preliminary-port/

If you can get your dad to bring up eLua on the mbed platform, I suspect you could do the conversion fairly easily compared to trying to convert your application to C++.

盗琴音 2024-10-08 12:02:03

手动移植代码,当您这样做时,您将学习 C++。 :D

Port the code manually, and as you do, you will learn C++. :D

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文