'return'에 해당되는 글 1건

  1. 2009.09.02 [C/C++] classifing function return value type...

[C/C++] classifing function return value type...

Language/C&C++ 2009.09.02 22:35
[[ blog 이사 과정에서 정확한 posting날짜가 분실됨. 년도와 분기 정도는 맞지 않을까? ]]

In terms of function's return value, I classify three types.

type 1 : Function may fail with quite high possibility. 
return value tells details about success or fail reason.
Ex.)

return_value == 0 : general success.
return_value > 0 : success with additional information [value represents additional information]
return_value < 0 : fails [value represents error code]

int open_service(...) {...}

type 2 : Function may fail with very low possibility.
return value tells the result or "success or fail".
Ex.)

return_value == NULL : fails.
otherwise : return_value is result.

Item* List::next() {...}
FILE* fopen(...) {...}

In this case, we may need additional function like "get_last_error()" - like MSVC's API.

type 3 : Function never fails.
return value is result, 'void' or instance itself to easy-next-use.
Ex.)

int get_id() {...}
void set_color(int color) {...}
Paint* Paint::set_color(int color) {...; return this;}
신고
tags : ,
Trackback 0 : Comment 0