学习C与C ++背景 [英] learning C with a C++ background

查看:82
本文介绍了学习C与C ++背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我昨天刚刚找到一份新工作,其中大部分编程都在
C完成。虽然我有几年的C ++经验和其他

面向对象语言,我在C中几乎没有。


我要找的是一本书(或其他一些资源)关于如何

学习C如果你已经知道C ++或者更准确地说,当你的唯一体验是面向对象的

语言时,如何使用

程序语言进行编程。


我发现自己想要模仿许多OO功能,而且我有这个错误的

印象。我需要知道源文件是如何组织的,我丢失了没有名称空间,类和标准的

库(容器,某人?),你如何应对在函数顶部的所有这些变量

定义中,你真的创建了

as-big-you-can-can-chars for strings等等。 。


几乎我在C ++中被告知和教导的所有内容似乎都需要在C中使用
。这对我来说是违反直觉的。难以克服。

有没有一本智慧的书可以帮助我理解

成语,设计模式或经常使用的建筑?

谢谢,

Jonathan

解决方案

jo *************** @ gmail.com 写道:

昨天我刚刚找到一份新工作,其中大部分编程工作都是在C. C完成。虽然我有几年的经验在C ++和其他面向对象的语言中,我在C中几乎没有。

你这个可怜的家伙!

我要找的是一本书(或其他一些资源)关于如果你已经了解C ++,如何学习C或者更准确地说,当你唯一的经验是面向对象的语言时,如何使用程序语言进行编程。

只需阅读K& R,开放的心态。

我发现自己想要模仿许多OO功能,而且我的印象是错误的。


这没有错,它可能不是惯用的C,但你可以用C写好,

干净的OO代码。

我需要知道源文件是如何组织的,我丢失了没有命名空间,类和标准库(容器,某人?),你如何应对所有这些变量
函数顶部的定义,你是否真的为字符串等创建了一个像你一样大的字符数组。

文件组织isn与C ++有很大不同,除了你的标题

定义一个功能界面而不是一个OO。


如果你可以使用C99,变量声明规则与C ++相同。如果

你遵循良好的编程习惯并使用简短的方法,

传统的C方式并不是什么大问题。

几乎所有我被告知和教导,以避免C ++似乎在C中需要。这对我来说是违反直觉的,很难克服。
是否有一本智慧的书可以帮助我理解
成语,设计模式或经常使用的构造?



学习一个好的C代码库。


-

Ian Collins。


Ian Collins写道:

jo *************** @ gmail.com 写道:

我只是昨天得到了一份新工作,其中大部分编程都是在C语言中完成的。虽然我有几年的C ++和其他面向对象语言的经验,但我在C语言中几乎没有。
你这个可怜的玩家!




:)谢谢

我正在寻找的是关于如果你已经了解C ++的如何学习C的书(或其他一些资源)。或者更确切地说,如果你的唯一体验是面向对象的语言,那么如何使用程序语言进行编程。


只需阅读K& R,开放的心态。




知道了。

我发现自己想模仿很多OO功能和我有
印象这是错误的。



这没有错,它可能不是惯用的C,但你可以写好,
在C中清理OO代码。




我发现Gtk库有点麻烦,例如,好像它是b / b
isn'' t C和C ++。我可能在这里错了,但这就是我给b $ b的印象。

如果可以使用C99,变量声明规则与C ++相同。




我不能。有趣的是,我今天花了二十分钟试图在''variable_name''之前理解一个

无效的标识符在记住之前必须在函数之上声明
变量。

几乎所有我被告知和教导的东西C中似乎需要避免使用C.这对我来说是违反直觉的,很难克服。
是否有一本智慧的书可以帮助我理解成语,设计模式或经常使用的构造?


研究一个好的C代码库。




我会,但我不是很好知道某些C代码是否好的位置是什么?或不是。

Jonathan


Jonathan Mcdougall写道:

Ian Collins写道:


研究一个好的C代码库。



我会,但我不知道是否有一些C代码是/
"良好的"或者没有。



看一下OpenSolaris中的一些新代码,比如ZFS:

http://cvs.opensolaris.org/source/xr...libzfs/普通/


-

Ian Collins。


I just got a new job yesterday where most of the programming is done in
C. Although I have several years of experience in C++ and other
object-oriented languages, I have next to none in C.

What I am looking for is a book (or some other resource) on "how to
learn C if you already know C++" or, more exactly, "how to program in a
procedural language when your only experience is with object-oriented
languages".

I find myself wanting to emulate many OO features and I have the
impression this is wrong. I need to know how source files are
organized, I''m lost without namespaces, classes and the standard
library (containers, someone?), how do you cope with all these variable
definitions at the top of a function, do you really create
as-big-as-you-can arrays of chars for strings, etc. etc.

Pretty much everything I was told and teached to avoid in C++ seem to
be needed in C. That''s counter-intuitive for me and hard to get over.
Is there a book of wisdom somewhere that could help me understand
idioms, design patterns or oft-used construction?

Thank you,
Jonathan

解决方案

jo***************@gmail.com wrote:

I just got a new job yesterday where most of the programming is done in
C. Although I have several years of experience in C++ and other
object-oriented languages, I have next to none in C.
You poor bugger!
What I am looking for is a book (or some other resource) on "how to
learn C if you already know C++" or, more exactly, "how to program in a
procedural language when your only experience is with object-oriented
languages".
Just read K&R, with an open mind.
I find myself wanting to emulate many OO features and I have the
impression this is wrong.
It''s not wrong, it might not be idiomatic C, but you can write good,
clean OO code in C.
I need to know how source files are
organized, I''m lost without namespaces, classes and the standard
library (containers, someone?), how do you cope with all these variable
definitions at the top of a function, do you really create
as-big-as-you-can arrays of chars for strings, etc. etc.
File organisation isn''t much different form C++, except your headers
define a functional interface rather than an OO one.

If you can use C99, variable declaration rules are the same as C++. If
you follow good programming practice and use short methods, the
traditional C way isn''t a big deal.
Pretty much everything I was told and teached to avoid in C++ seem to
be needed in C. That''s counter-intuitive for me and hard to get over.
Is there a book of wisdom somewhere that could help me understand
idioms, design patterns or oft-used construction?


Study a good C code base.

--
Ian Collins.


Ian Collins wrote:

jo***************@gmail.com wrote:

I just got a new job yesterday where most of the programming is done in
C. Although I have several years of experience in C++ and other
object-oriented languages, I have next to none in C.
You poor bugger!



:) Thanks

What I am looking for is a book (or some other resource) on "how to
learn C if you already know C++" or, more exactly, "how to program in a
procedural language when your only experience is with object-oriented
languages".


Just read K&R, with an open mind.



Got that.

I find myself wanting to emulate many OO features and I have the
impression this is wrong.



It''s not wrong, it might not be idiomatic C, but you can write good,
clean OO code in C.



I find the Gtk library to be a bit cumbersome, for example, as if it
wasn''t C nor C++. I might be wrong here, but that''s the impression I
have.
If you can use C99, variable declaration rules are the same as C++.



I can''t. Funny, I spent twenty minutes today trying to understand a
"invalid identifier before ''variable_name''" before remembering that
variables must be declared on top of a function.

Pretty much everything I was told and teached to avoid in C++ seem to
be needed in C. That''s counter-intuitive for me and hard to get over.
Is there a book of wisdom somewhere that could help me understand
idioms, design patterns or oft-used construction?


Study a good C code base.



I will, but I am not in a good position of knowing whether some C code
is "good" or not.
Jonathan


Jonathan Mcdougall wrote:

Ian Collins wrote:


Study a good C code base.


I will, but I am not in a good position of knowing whether some C code
is "good" or not.


Have a look at some of the newer code in OpenSolaris, something like ZFS:

http://cvs.opensolaris.org/source/xr...libzfs/common/

--
Ian Collins.


这篇关于学习C与C ++背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆