本文介绍了C程序设计资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自OO背景(C#/ java)我正在寻找资源来学习如何设计纯C程序。

Coming from a OO background (C#/java) I'm looking for resources to learn how to design pure C programs well.

虽然我熟悉C的语法,而且我可以编写小程序,但我不确定采用更大的应用程序的方法,以及什么技术采用。任何你可以推荐的东西。

Whilst i'm familiar with the syntax of C, and i can write small programs, i'm unsure of the approach to take for larger applications, and what techniques to employ. Anything you guys can recommend.

编辑:我很高兴完全放弃OO为C编程的目的,我的兴趣是学习如何构建一个程序,没有OO,我想了解如何使用程序语言设计程序的好方法,如C。

I'm happy to completly abandon OO for the purposes of programming in C, my interest is in learning how to structure a program without OO, I want to learn about good ways of designing programs in procedural languages such as C.

推荐答案

有一系列unix书籍,其中包括大部分经典的C / Unix作品。对于Windows上的C编程,Petzold的可能是最好的开始。

This posting has a list of unix books which includes most of the classic C/Unix works. For C programming on Windows, Petzold's Programming Windows is probably the best start.

对于C程序设计,一些unix编程书籍将会告诉您的代码段,但我不知道C程序体系结构一书。

For C program design, some of the unix programming books will tell you snippets but I'm not aware of a 'C program architecture' book.

如果你习惯了java,C程序的一些提示是:

If you're used to java, some tips for C programing are:


  1. 的noreferrer>。通常当您调用过程时,您将需要在调用者的堆栈帧中分配变量,并将其指向要调用的过程。这将比通过,更不容易出错。请在适当的情况下执行此操作。

  1. Make use of stack. Often when you call a procedure you will want to have variables allocated in the caller's stack frame and pass pointers to them into the procedure you want to call. This will be substantially faster than dynamically allocating memory with malloc() and much less error prone. Do this wherever appropriate.

C不执行,所以动态分配数据项是更加狡猾的,你必须跟踪它们到和。它们对于通用错误处理机制代替结构化异常处理功能非常有用。

Get to know what setjmp() and longjmp() do. They can be quite useful for generic error handler mechanisms in lieu of structured exception handling functionality.

见(3)。

是你的朋友。 更加友善。

Lint is your friend. Splint is even friendlier.

学习是什么,即使可以,您也不应该使用它。

Learn what the preprocessor does and what you shouldn't do with it even if you can.

了解,,和其他低级建筑奥秘。与民意相反,这些并不是火箭科学。如果你有兴趣,请尝试用汇编语言进行汇总,并获得有关的知识。对于您C程序中的内容,您将会做很多工作。

Learn the ins and outs of endian-ness, word alignment, pointer arithmetic and other low-level architectural arcana. Contrary to popular opinion these are not rocket science. If you're feeling keen, try dabbling in assembly language and get a working knowledge of that. It will do much for your understanding of what's going on in your C program.

C没有模块范围的概念,因此计划使用包含的原型声明和使用和来创建私有范围和导入标识符。

C has no concept of module scope, so plan your use of includes, prototype declarations, and use of extern and static to make private scopes and import identifiers.

C中的GUI编程对于 ,或在许多情况下,C的最佳用途是作为基本上以其他​​方式编写的应用程序的核心高性能引擎。

Apropos of (10) learn the C API of at least one scripting language such as Tcl, Lua or Python. In many cases the best use of C is as a core high-performance engine on an application that is substantially written in something else.

构造函数的等价物是一个初始化函数,您可以将一个指针传递给要设置的项目。通常,您可以通过调用函数看起来像 setup_foo(& my_foo)。最好将分配与初始化分开,因为您可以使用此函数初始化在堆栈上分配的项目。类似的原则适用于析构函数。

The equivalent of a constructor is an initialising function where you pass in a pointer to the item you want set up. Often you can see this in the form of a call to the function that looks like setup_foo(&my_foo). It's better to separate allocation from initialising, as you can use this function to initialise an item you have allocated on the stack. A similar principle applies to destructors.

大多数人发现关于书面匈牙利语的可读性。这个例外是匈牙利语的本地人,他们通常会发现匈牙利语符号与 Stevens 和 和(如果在Windows上工作)和任何其他经典C / Unix工作。阅读,用铅笔涂抹在他们上面,一般与书籍交流。

C/Unix books, even really good ones like the ones written by the late W Richard Stevens tend to be available secondhand quite cheaply through Amazon marketplace. In no particular order, get a copy of K&R, Stevens APUE and UNP 1 & 2, the Dragon book, Rochkind, Programming Pearls, Petzold and Richter (if working on Windows) and any of the other classic C/Unix works. Read, scribble on them with a pencil and generally interact with the books.

有很多很好的资源在网络上。

There are many, many good C/Unix programming resources on the web.

阅读并了解和一些元数据讨论为什么以及诫命背后的地方。这在一定程度上显示了它的年龄,尽管大部分仍然是相关的,而且模糊的编译器仍然是是你的朋友,如果你想写解析器。

Lex and Yacc are your friend if you want to write parsers.

作为Navicore ,Hanson的是一系列示例的模块化架构的接口/实现设计的破坏。我已经听说过这本书,听说过很好的事情,虽然我不能声称自己已经阅读了。除了上面描述的C语言之外,这个概念可以说是良好的程序设计的核心。实际上,其他程序语言,如Modula-2实际上使这个概念在设计中是明确的。这可能是打印C程序架构书中最接近的一个。

As Navicore points out below (+1), Hanson's 'C Interfaces and Implementations' is a run-down on interface/implementation design for modular architecture with a bunch of examples. I have actually heard of this book and heard good things about it, although I can't claim to have read it. Aside from the C idioms that I've described above, this concept is arguably the core of good procedural design. In fact, other procedural languages such as Modula-2 actually make this concept explicit in their design. This might be the closest thing to a 'C Program Architecture' book in print.

阅读。

这篇关于C程序设计资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 03:22