我应该将程序从C更新为现代C或C ++吗?

时间:2023-01-13 10:40:22

I have an old program written in C from the 1990's. I would like to update it so that it will work for the next persons and on modern compilers. Currently I am using a really old version of TurboC to make changes. Should I be focusing on rewriting this in modern C or C++? Which will be the easiest to bring this code up to date without having to rewrite too much and be able to reuse most of the existing code?

我有一个旧的程序,用1990年代的C编写。我想更新它,以便它适用于下一个人和现代编译器。目前我正在使用一个非常旧版本的TurboC来进行更改。我应该专注于在现代C或C ++中重写它吗?最简单的方法是使这些代码更新,而不必重写太多而且能够重用大部分现有代码?

My programming background has mostly been in hprogramming languages like Perl, Python, PHP, Powershell, and Visual Basic, so I am not too familiar with the differences between C and C++.

我的编程背景主要是像Perl,Python,PHP,Powershell和Visual Basic这样的hprogramming语言,所以我不太熟悉C和C ++之间的差异。

5 个解决方案

#1


5  

C and C++ are different languages, not different versions of the same language. Stick to C, although you could use the fancy features of newer versions of the standard, like C99.

C和C ++是不同的语言,而不是同一语言的不同版本。坚持C,虽然您可以使用标准的新版本的奇特功能,如C99。

#2


5  

Your last sentence pretty much answers your sentiment. If you aren't familiar with the differences and you only know older languages I wouldn't update this program unless there is something horribly wrong with it that is affecting many users.

你的最后一句话几乎可以回答你的情绪。如果您不熟悉这些差异,并且您只知道较旧的语言,我将不会更新此程序,除非它有可怕的错误影响许多用户。

You could update it just within the C world to adhere to C99 or C11 if you have a newer compiler

如果你有一个更新的编译器,你可以在C世界内更新它以符合C99或C11

#3


3  

Given:

have an old program written in C from the 1990's.

有一个旧的程序,从1990年代用C语言编写。

You have two questions:

你有两个问题:

Should I be focusing on rewriting this in modern C? Maybe, maybe not. I would try to adhere to a standard C89, C99, or C11. This mainly depends on your tools and how much new development will happen.

我应该专注于在现代C中重写这个吗?也许,也许不是。我会尝试遵循标准的C89,C99或C11。这主要取决于您的工具以及将会发生多少新的开发。

Do you like declaring variables other than at the beginning of scope? If so, then possibly update to C99. Are you using any tools that really like C89 and show errors or warnings with C99 conventions? If so, then stick to C89.

你喜欢声明除范围开头之外的变量吗?如果是这样,那么可能更新到C99。您是否正在使用任何真正喜欢C89的工具并使用C99惯例显示错误或警告?如果是这样,那么坚持C89。

If the program is continually being updated and you are hiring young people, then newer conventions might be beneficial.

如果该计划不断更新并且您正在招聘年轻人,那么较新的惯例可能会有所帮助。

Should I be focusing on rewriting this in C++? No.

我应该专注于用C ++重写吗?没有。

#4


3  

Most well-written C programs are also valid C++ programs, or require just a little adaptation. The opposite is not true.

大多数编写良好的C程序也是有效的C ++程序,或者只需要一点点改编。反之则不然。

It's probably easier to stick with ANSI/ISO C and leave both doors open for the next maintainer.

坚持使用ANSI / ISO C可能更容易,并为下一个维护者打开两扇门。

#5


2  

It's probably about the same effort to move to a modern C compiler vs. a modern C++ compiler. The evolution of C and C++ have diverged where each has similar features but they're not source compatible.

转向现代C编译器与现代C ++编译器可能大致相同。 C和C ++的发展有所不同,每个都有类似的功能,但它们不是源兼容的。

There are a few factors that would lead me to choose to update to C++:

有几个因素会导致我选择更新到C ++:

  • Modern C doesn't seem to enjoy as much support as C++. For example many new things in C seem to get implemented only as required by C++, especially in the Microsoft world. VS doesn't even support C99 except for what's in C++, let alone C11.

    Modern C似乎没有C ++那么多的支持。例如,C中的许多新东西似乎只能按照C ++的要求实现,特别是在Microsoft世界中。 VS甚至不支持C99,除了C ++中的内容,更不用说C11了。

  • C++ is a better C: "C++ is "a better C" in the sense that it supports the styles of programming done using C with better type checking and more notational support (without loss of efficiency)." This is still true of modern versions of C.

    C ++是一个更好的C:“C ++是一个更好的C”,因为它支持使用C完成的编程风格,具有更好的类型检查和更多的符号支持(不会降低效率)。“现代版本的C仍然如此。

  • C++ adds features that support some very powerful techniques. Really making use of them may be best left to library developers, but that means C++ can support really great libraries.

    C ++增加了支持一些非常强大的技术的功能。真正利用它们可能最好留给库开发人员,但这意味着C ++可以支持真正优秀的库。

#1


5  

C and C++ are different languages, not different versions of the same language. Stick to C, although you could use the fancy features of newer versions of the standard, like C99.

C和C ++是不同的语言,而不是同一语言的不同版本。坚持C,虽然您可以使用标准的新版本的奇特功能,如C99。

#2


5  

Your last sentence pretty much answers your sentiment. If you aren't familiar with the differences and you only know older languages I wouldn't update this program unless there is something horribly wrong with it that is affecting many users.

你的最后一句话几乎可以回答你的情绪。如果您不熟悉这些差异,并且您只知道较旧的语言,我将不会更新此程序,除非它有可怕的错误影响许多用户。

You could update it just within the C world to adhere to C99 or C11 if you have a newer compiler

如果你有一个更新的编译器,你可以在C世界内更新它以符合C99或C11

#3


3  

Given:

have an old program written in C from the 1990's.

有一个旧的程序,从1990年代用C语言编写。

You have two questions:

你有两个问题:

Should I be focusing on rewriting this in modern C? Maybe, maybe not. I would try to adhere to a standard C89, C99, or C11. This mainly depends on your tools and how much new development will happen.

我应该专注于在现代C中重写这个吗?也许,也许不是。我会尝试遵循标准的C89,C99或C11。这主要取决于您的工具以及将会发生多少新的开发。

Do you like declaring variables other than at the beginning of scope? If so, then possibly update to C99. Are you using any tools that really like C89 and show errors or warnings with C99 conventions? If so, then stick to C89.

你喜欢声明除范围开头之外的变量吗?如果是这样,那么可能更新到C99。您是否正在使用任何真正喜欢C89的工具并使用C99惯例显示错误或警告?如果是这样,那么坚持C89。

If the program is continually being updated and you are hiring young people, then newer conventions might be beneficial.

如果该计划不断更新并且您正在招聘年轻人,那么较新的惯例可能会有所帮助。

Should I be focusing on rewriting this in C++? No.

我应该专注于用C ++重写吗?没有。

#4


3  

Most well-written C programs are also valid C++ programs, or require just a little adaptation. The opposite is not true.

大多数编写良好的C程序也是有效的C ++程序,或者只需要一点点改编。反之则不然。

It's probably easier to stick with ANSI/ISO C and leave both doors open for the next maintainer.

坚持使用ANSI / ISO C可能更容易,并为下一个维护者打开两扇门。

#5


2  

It's probably about the same effort to move to a modern C compiler vs. a modern C++ compiler. The evolution of C and C++ have diverged where each has similar features but they're not source compatible.

转向现代C编译器与现代C ++编译器可能大致相同。 C和C ++的发展有所不同,每个都有类似的功能,但它们不是源兼容的。

There are a few factors that would lead me to choose to update to C++:

有几个因素会导致我选择更新到C ++:

  • Modern C doesn't seem to enjoy as much support as C++. For example many new things in C seem to get implemented only as required by C++, especially in the Microsoft world. VS doesn't even support C99 except for what's in C++, let alone C11.

    Modern C似乎没有C ++那么多的支持。例如,C中的许多新东西似乎只能按照C ++的要求实现,特别是在Microsoft世界中。 VS甚至不支持C99,除了C ++中的内容,更不用说C11了。

  • C++ is a better C: "C++ is "a better C" in the sense that it supports the styles of programming done using C with better type checking and more notational support (without loss of efficiency)." This is still true of modern versions of C.

    C ++是一个更好的C:“C ++是一个更好的C”,因为它支持使用C完成的编程风格,具有更好的类型检查和更多的符号支持(不会降低效率)。“现代版本的C仍然如此。

  • C++ adds features that support some very powerful techniques. Really making use of them may be best left to library developers, but that means C++ can support really great libraries.

    C ++增加了支持一些非常强大的技术的功能。真正利用它们可能最好留给库开发人员,但这意味着C ++可以支持真正优秀的库。