http://www.kt.rim.or.jp/~kbk/zakkicho/index.html - 11/21/09 07:05:07 - 10/07/08 13:59:44
2009年11月02日
・寒い 懐が(笑) まあそれはおいといて、一気に気温が下がったみたいですね。
・格ゲー 鉄拳は最近になって6が出ましたが、どちらかというとわたしはヴァーチャファイターのほうが 好きだったり。
・ついった なんかわたしのついったのTLで見かける人で、 8月以降退職にしたとかいう人をよく見かけるような希ガス。
C++ もうちょっと使ってもいいんじゃね? というお話。
Embedded Systems Design - Embedded.com Poor reasons for rejecting C++ Choosing a programming language should be a well-informed choice. By Dan Saks Embedded.com (08/20/09, 03:00:00 H? EDT) My colleague, Michael Barr, wrote an interesting piece earlier this month, entitled "Real men program in C."1 I won't try to summarize it--you can read it yourself. The article provoked numerous comments from readers citing reasons to prefer C over C++. I disagree with several of those comments, and I'd like to say a little in reply to each. My colleague の Michael Barr が今月初め(2009年8月)、"Real men program in C."1 というタイトルの興味深い一篇を書きました。わたしはここでそのまとめを書くつも りはありませんが ここで 読むことができます。 The article provoked numerous comments from readers citing reasons to prefer C over C++. I disagree with several of those comments, and I'd like to say a little in reply to each. One reader wrote, "Just for the fun of it you might as well want to have a look at what Linus Torvalds thinks about C and C++,"followed by the URL to the remark (which I've omitted intentionally). ある読者曰く「それが楽しいからですよ。Linus Torvalds が C や C++ について考えたような ことをあなたも望んでいるかもしれませんけど」 followed by the URL to the remark (which I've omitted intentionally). I suppose reading what Torvalds wrote would be fun if you like reading rants. It wasn't fun for me. It's provocative but not well grounded, as explained by my friend and colleague Steve Dewhurst.2 Torvalds has made positive contributions to the computing industry, but this wasn't one of them. あなたが rants を読むことが好きならば、Torvalds が書いたことを読むのは楽しいことでしょ う。わたしにとってはそうではありませんでしたが。彼の発言は、わたしの友人で colleague の Steve Dewhurst が説明しているように刺激的なものではありますが well grounded ではあ りませんでした.2。Torvalds はなるほど computing industry に対して positive contributions したでしょうが、今回のこれはその中には含まれません。 Another reader wrote, "I've studied C++ but never used it professionally and, the more I study it, the less I think it appropriate for embedded use. It's not just that it is expensive in terms of resources; it encourages you to do too many risky things. It's bad enough that you can do things like dynamic allocation and recursion in C but, in C++, the language will do it without your ever realizing it, unless you know what its [sic] doing behind the scenes..." 別の読者曰く 「"わたしはC++を学びましたが professionally にそれを使ったことはあり ませんでしたしさらに学んだものの組み込み用途に適しているとは思わなくなったのです。It's not just that it is expensive in terms of resources; リソースという観点では高価ではあ りませんでしたが、リスクが高いことを encourage しています。それはC で動的割付をしたり 再帰を行うのと同じくらい悪いことなのですがC++ ではそれをあなたが認識しないところで行う のですunless you know what its [sic] doing behind the scenes..."」 I have used C++ for prototyping embedded systems and consulted for others who have developed production systems in C++. The more I use it and see it used, the more convinced I am that it's preferable to C, when available. わたしはC++を、組み込みシステムのプロトタイピングやC++ を使ってproduction system を開 発している他の人のコンサルトに使っています。 The more I use it and see it used, the more convinced I am that it's preferable to C, when available. Rather than encourage risky behavior, many of C++'s core features--such as classes, access control, constructors, destructors, references and overloading--work hand-in-hand with stricter type checking to help reign in the riskiest parts of C. While I agree that typical C++ code tends to be a bit larger and slower than comparable C, the added expense is rarely prohibitive (on the order of 10-15%). I've had little problem tuning time-critical code, such as interrupt handlers, to be as or more efficient than it would be in C. risky behavior を強調するのではなく、C++ のコア機能の多く- クラス、アクセス制御、コン ストラクター、デストラクター、リファレンス、オーバーローディング -work hand-in-hand with stricter type checking to help reign in the riskiest parts of C. 典型的なC++ のコ ードはCと比較して、大きく遅くなる傾向があることには私も賛成しますが、増加した分が高価 につくことはほとんどありません (on the order of 10-15%)。C ではより効率よく書けるであ ろう割り込みハンドラーのような time-critical なコードのチューニングで多少問題があった ことがあります。 I know of no place where the C++ language performs dynamic allocation or recursion behind the scenes. Indeed, your code might call a function that uses dynamic allocation or recursion, but this is no more a problem in C++ than in C. In fact, C++ supports simple compile- and link-time techniques you can use to explicitly prevent using dynamic allocation, which I'll cover in an upcoming column. I know of no place where the C++ language performs dynamic allocation or recursion behind the scenes. Indeed, あなたのコードは動的割付や再帰を使っている関数を呼び出すかもしれませんが、C とは違いそ れはもはや C++ では問題になりません。事実、C++ は動的割付をはっきりとした形で防ぐため に使うことのできる単純なコンパイル時テクニックやリンク時テクニックをサポートしています (いずれこのコラムで紹介します)。 Yet another reader wrote, "The only part of object orientation that is a must-have in embedded systems is private encapsulation. C supports this nicely enough with static variables declared at file scope." さらに別の読者曰く"組み込みシステムになくてはならないオブジェクト指向の要素と言え ばprivate encapsulation だけだ。C ではこれをファイルスコープで static 変数を宣言するこ とで十分にサポートする。" While I agree with the basic sentiment of the first sentence, I wouldn't word it so strongly. I would say that the single most useful feature of C++ that's absent from C is classes with private access control. I would not call it a "must-have" feature simply because programmers do write viable embedded systems in C--without classes. However, you can write better embedded systems with classes. I wouldn't want to code without them. 最初のセンテンスの basic sentiment には賛成しますがそれほど強くは言いません。わたしは private なアクセスコントロールを持ったクラスが、Cには欠けているC++ のもっとも有用な単 一の機能だと主張します。わたしはそれを単純に "must-have" feature (必須の機能) とは呼びません。なぜならプログラマーがクラスを使わない C-- で viable な組み込みシステ ムを書いているからです。とはいえ、あなたがクラスを使ったより良い組み込みシステムを書く ことは可能です。クラス抜きではわたしはコードを書く気にはならないでしょう。 On the other hand, I disagree that C supports access control"nicely enough with static variables declared at file scope". I believe the reader is referring to the common technique whereby you: その一方でわたしは C がサポートしているアクセス制御が"nicely enough with static variables declared at file scope". (ファイルスコープで宣言された static 変数で十 分役に立つ)という主張に反対します。 I believe the reader is referring to the common technique whereby you: ・ place the data declarations for the encapsulated data structure in a separate source file, カプセル化するデータ構造体のデータ宣言を分割したソースファイルにおく ・ add the keyword static to each data declaration so that the data has internal linkage,3 and static というキーワードをそれぞれのデータ宣言のために追加しているので 対象のデータは内部リンケージを持つことになる ・ define non-inline functions with external linkage in that same source file to provide the publicly accessible operations on the encapsulated data. カプセル化されたデータに対する publicly accessible operations を提供するために 同一のソースファイル中で外部リンケージを持った非インライン関数を定義する I refer to this technique as encapsulation by separate compilation. It works "nicely enough" only if you're willing to accept the following: わたしはこの技法を分割コンパイルによるカプセル化と見なしています。この技法は、以下の項 目をあなたが accept したときにのみ"nicely enough" に働きます。 ・ Your code will probably be both bigger and slower than it would be if the data were not encapsulated, because code outside the encapsulation unit can access the data only through non-inline function calls. あなたのコードは、カプセル化をしなかった場合に比べてサイズが大きく、実行速度も 遅くなる可能性がありますなぜならカプセル化のユニットの外側にあるコードはインラ イン化していない関数呼び出しを通じてのみデータへのアクセスが可能だからです。 ・ Each program can have at most one instance of the encapsulated data structure, unless you're willing to accept even bigger and slower code that comes with using an ad hoc memory manager. 各プログラムは、アドホックなメモリーマネージャを使ったことによるさらに大きく遅いコ ードを受容しない限り高々一つのカプセル化されたデータ構造のインスタンスしか持つこと ができません。 C++ classes don't have these limitations. C++ のクラスにはこういった制限がありません。 The same reader added that "Initialization through constructors is not something you desire; in fact you will want to avoid this for security reasons and for reduced bootup time." この読者はこうも言っています"コンストラクターを通じての初期化はあなたの望んだなに かではありません。実際、セキュリティ上の理由や起動時間の短縮のためにこれを取り除きたく なるでしょう。" I strongly disagree with this statement. Initialization by constructors is highly desirable. I'd rank constructors and destructors as the second most useful C++ feature that's absent from C (after classes with access control). Failure to properly initialize objects can lead to security problems, and constructors go a long way toward ensuring proper initialization. (Order-dependencies in member initializers can be hazardous, but you can use static analysis tools that will alert you to such hazards.) I would be interested to see concrete examples of how using constructors can cause security problems. So would Robert Secord, author of Secure Coding in C and C++ (2005, Addison-Wesley) and The CERT C Secure Coding Standard (2008, Addison-Wesley). わたしはこの statement には強く反対します。コンストラクターを使った初期化は highly desirable です。わたしはコンストラクターとデストラクターを、C にはない、 C++の二番目に 便利な機能であると rank します(一番目はアクセス制御を持ったクラス)。適切な初期化に失敗 したオブジェクトはセキュリティ上の問題に繋がる可能性があります。そしてコンストラクター は適切な初期化を保証しているのです(メンバーの初期化に関する順序依存は hazardous となる 可能性がありますがそのような hazardous を警告してくれる静的解析ツールが使えます)。 I would be interested to see concrete examples of how using constructors can cause security problems. コンストラクターがセキュリティ上の問題を引き起こす可能性のある使い方の 具体的な例 So would Robert Secord, author of Secure Coding in C and C++ (2005, Addison-Wesley) and The CERT C Secure Coding Standard (2008, Addison-Wesley). If you're concerned about startup time, C++ offers features such as"placement new" to give you greater control over when constructors execute. Using placement new, you can defer initialization for selected objects until after system startup. I expect to cover this in the not-too-distant future. もしあなたが起動時間に関心を持っているのなら、C++ には "placement new" のよ うな機能があります。これはコンストラクターを実行するときにgreater control をあなたに提 供するものです。placement new を使うことで選択したオブジェクトの初期化をシステムが起動 が完了するまで遅らせることが可能です。 I expect to cover this in the not-too-distant future. Despite my avowed preference for C++ over C, I still recognize that many of my readers have legitimate reasons to use C, such as the lack of an adequate C++ compiler for the intended target platform.4 I will continue to write about topics of interest to both C and C++ programmers, in part because I think your programming language choice should be well-informed. Between the time I wrote this column and the time it was posted, further comments on Michael Barr's column pursued the question of whether constructors can lead to security problems. The reader who originally raised this issue explained that the problem "isn't because of the language, but because of the unreliable nature of RAM. there could be days, weeks or years from the point of initialization to the point where the variable is used. If you rely on the initialization values, you leave the safety in the hands of the RAM manufacturer." It sounds to me like the problem he's describing is, by his own admission, independent of the use of constructors. I still see no basis for the claim that one should avoid using constructors for security reasons. Dan Saks is president of Saks & Associates, a C/C++ training and consulting company. For more information about Dan Saks, visit his website at www.dansaks.com. Dan also welcomes your feedback: e-mail him at dan@dansaks.com. For more information about Dan click here . Endnotes: 1. Barr, Michael, "Real men program in C", Embedded.com, August 1, 2009. Available online at www.embedded.com/columns/barrcode/218600142. 2. Kalev, Danny, C++ Reference Guide: A Response to Linus Torvalds' C++ Diatribe. Posted online November 14, 2008 at www.informit.com/guides/content.aspx?g=cplusplus&seqNum=411. 3. Saks, Dan, "Linkage in C and C++", Embedded Systems Design, March, 2008, page 9. Available online at www.embedded.com/columns/technicalinsights/206901036. 4. Saks, Dan, "Moving to Higher Ground", Embedded Systems Programming, October, 2003, page 45. Available online at www.embedded.com/columns/programmingpointers/15200968
- 2ちゃんねるの規制について -OKWaveなんでOKWaveに2ちゃんの規制の解除をお願いするんだろう?
- 抜き出しマクロ(3) -OKWave
なにキレてるんですか? 長いなら見なければいいでしょう? 僕はマクロ初心者なので。- データ抜き出しマクロについて -OKWave
- 抜き出しマクロについて(2) -OKWave
- データ抜き出しマクロの改良 -OKWave
回答の削除の仕方を教えてください。 なかったことに。 回答しなきゃよかった。- http://www.naucon.org/~fukuhara/youi/d/text0911.html#091101_2
ここにもホイホイさん- 2009年度日本OSS貢献者賞、授賞式を開催 - @IT
小崎氏は「Linuxカーネルの開発は難しくなりすぎて、若い人がなかなか入ってこないことが世界的に課題。そこで、開発者を増やしていこうという活動を展開中だ」と述べた。「コスト削減というのは、オープンソースを使う目的ではなく結果。コスト削減のためだけにオープンソースを使っても、その恩恵を受けられなくなる」- ASCII.jp:8月が終わらない「涼宮ハルヒの憂鬱」第3巻が登場
ショップスタッフによると、この日入荷したタイトルとしては確実にブッチギリの売れ行きを見せているとのことだが、 ハルヒシリーズの第1シーズンや第2シーズン第1巻の売れ行きに比べると流石に落ち着いているようだ。- くねくね科学探検日記 iPhone とクラウド
- char形のポインタの内容は(基本情報16年午後第6問に関して) -OKWave
- C++初心者でとても困っています -OKWave
調べながらやればできると思い引き受けてしまったのですが、グーグルのソースコードが検索できるサイトをみても専門のサイトをみても全然わかりません。- コンパイルエラーの英語の読み方 -OKWave
- http://www.openbsd.org/images/rack2009.jpg
- [Lua]関数と変数は装備しないと意味ない
- 「DSi LL」名前の由来はやっぱり「LLサイズ」だから? 任天堂に聞いてみた(ITmedia Gamez) - Yahoo!ニュース
「『ニンテンドーDSi LL』の名前についてですが、ご想像のとおり、洋服などの“LLサイズ”から、“より大きい”というイメージを表すために命名したものです」(任天堂)- Zコンビネータ - T/O
- 猫と仲良くなる方法も!かわいいだけじゃない、街で暮らす「野良猫」たちの魅力 - はてなブックマークニュース
- 就活中です! - hogeなlog
- 商品詳細: 三平 三平(みひら さんぺい)
- 商品詳細: 1/16 ブレイダー/スキャニー/ビゴラス
- Chapter7 ラムダ式(後編) - @IT
- Bpstudy26
- App Storeエフェクト―iPhoneアプリのどん底に向けての競争 : Gizmodo Japan(ギズモード・ジャパン), ガジェット情報満載ブログ
- egrepの使い方を教えてください。 - Yahoo!知恵袋