When should we use asserts in C?

前端 未结 9 1733
孤街浪徒
孤街浪徒 2020-12-02 11:21

I am writing a function in C. As a matter of style, when is it good to use assert compared to returning an error code. Lets say the function is dividing two numbers. Should

9条回答
  •  北海茫月
    2020-12-02 12:10

    In general, asserts are for the programmer (i.e. you) to find logic/programming errors before releasing the program to real users. Asserts should not be used for detecting runtime input errors -- use error codes for these.

提交回复
热议问题