私は職場で従来のCコードベースを持っていますが、私は以下のようなスタイルの関数実装がたくさんあります。私はそれはかなり鈍角見つけ、私は同様の機能を実装する必要があるときに私がやって終わるCはパラメータを過度に使用していますか?
myOutPtr = DoStuff(myInPtr, myOutPtr, myError, &myAmount);
:
NewDoStuffを使用してlong NewDoStuff(char *inPtr, char *error)
{
long amount = 0;
*error = 0;
// Read bytes from inPtr and decode them as a long storing in amount.
return amount;
}
を:
myAmount = NewDoStuff(myInPtr, myError);
myOutPtr += sprintf (myOutPtr, "%d", myAmount);
DoStuffを使用して
char *DoStuff(char *inPtr, char *outPtr, char *error, long *amount)
{
*error = 0;
*amount = 0;
// Read bytes from inPtr and decode them as a long storing in amount
// before returning as a formatted string in outPtr.
return (outPtr);
}
私はできませんpがありますが、私が一番上の例で欠けているものがあるのだろうかと疑問に思っているのですが、そのタイプのアプローチを使う良い理由はありますか?
+ = sprintfは何ですか? – Uri
http://msdn.microsoft.com/en-us/library/ybk95axf(VS.71).aspxは、文字列を書き込み、次にポインタを書き込まれたバイト数だけ前方に移動します。 – sipwiz
+ =ではなく、+ =でないはずですか? –