本文介绍了学习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语言编程的目的,我的兴趣是学习如何构建一个程序如果没有面向对象,我想了解在程序语言如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.

推荐答案

This发布已包括大部分的经典C的UNIX书籍列表/ 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. Make 的。通常情况下,当你调用一个过程,你会想在调用者的堆栈帧分配的变量,并通过指针他们进入你要调用的程序。这将是比和更容易出错。为此酌情。

  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没有做,以便动态地分配数据项是更繁琐你必须跟踪它们来在栈上分配的变量(参见图1)更地道,他们都是适用的。另外,你也不必释放它们 - 这是局部变量的奖金

C doesn't do garbage collection, so dynamically allocating data items is more fiddly and you have to keep track of them to make sure they get freed. Variables allocated on the stack (see 1) are more 'idiomatic' where they are applicable. Plus, you don't have to free them - this is a bonus for local variables.

(2),考虑的一个架构,你的职责进出使用堆栈按返回一个状态或错误code和传递数据中肯(1)。

Apropos of (2), consider an architecture where your functions return a status or error code and pass data in and out using the stack as per (1).

去了解和做。他们可以成为代替的结构化异常处理功能的通用错误处理机制相当有用的。

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$c>extern和使私人范围和导入的标识符。

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.

GUI编程是所有的

(10)中肯学习至少一个脚本语言的C API,如,的或的在许多情况下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.

大多数人觉得大约为可读书面匈牙利。唯一的例外是母语匈牙利语音箱,谁通常会发现大约为清晰的<一个匈牙利命名法href=\"http://www.google.co.uk/images?hl=en&expIds=17259,27491,27586,27812,27817&xhr=t&q=cuneiform&cp=4&client=firefox-a&hs=kwg&rls=org.mozilla%3aen-GB%3aofficial&um=1&ie=UTF-8&source=univ&ei=c37zTP-5Lo-1hAeIwenDCQ&sa=X&oi=image_result_group&ct=title&resnum=4&sqi=2&ved=0CEMQsAQwAw&biw=1200&bih=815\">Cuneiform..不幸的是匈牙利命名法被广泛encounterd在Windows软件和整个Win32 API的使用它,对软件编写的这个平台上的易读性的预期效果。

Most people find Hungarian notation about as readable as written Hungarian. The exception to this is native Hungarian speakers, who typically find Hungarian notation about as legible as Cuneiform.. Unfortunately Hungarian notation is widely encounterd in Windows software and the entire Win32 API uses it, with the expected effects on the legibility of software written on this platform.

C / Unix的书籍,竟然真的好喜欢那些由已故的理查德·史蒂文斯写的那些倾向于通过亚马逊的市场可用二手相当便宜。在没有特定的顺序,得到史蒂文斯的和 &安培; 2,的的的 并的(如果工作在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.

阅读并了解十戒和部分荟萃作为讨论的原因是与戒律背后wherefores。这正显示出它的年龄在一定程度上,虽然大部分仍是相关的,晦涩的编译器仍然quite常见的嵌入式系统世界。

Read and understand the Ten Commandments of C Programming and some of the meta discussion as to the why's and wherefores behind the commandments. This is showing its age to a certain extent, although most of it is still relevant and obscure compilers are still quite common in the embedded systems world.

是你的朋友。

作为Navicore points如下(+1),汉森的是一个破败接口/实现设计的模块化架构,一堆例子。其实我也听说过这本书,听到好东西吧,虽然我不能宣称已经阅读。除此之外我上面描述的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:21