7
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

新入社員がよくやるC/C++のミス

Last updated at Posted at 2018-08-07

新人教育を担当

新卒プログラマをそこそこ一人前にするのがミッション。
でも、コード書かせるとまぁまぁ同じようなミスをする。
よく使うのがC/C++なのでこんなタイトル。
言語関係ないものもあるかな

free/deleteしない。間違っている

必ずやる。
単純な忘れ以外だと
delete[] じゃない とか、
newしたときのアドレスを持っていないか、変更してしまっている。

sizeofでポインタを指定する

正しいこともあるんだけど、だいたい間違い。

memmoveでなくmemcpyを使う

同一バッファ内で移動させたいときはmemmoveを使う。前づめとか。
memcpyで、領域が重なっていたときの挙動は不定…

変数名がaとかbとか

リーダブルコード読んでもらってるんだけどなぁ
試行錯誤したコードをそのまま採用しがち

コピペしてきたコードが動かない。説明できない。

必須のヘッダをインクルードしてないとか、変数名が違うとか。
理解しないでコピペするから、なんで動かないかわからない。
当然、コードの説明もできない。

++hogeとhoge++の違いを意識しないで使う

あんまり使い分けることもない気がするけど
このミスで結構時間とられたみたい。

7
5
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?