One bug I encountered and some thoughts

I met a bug recently, it’s because I didn’t notice the return value of a system call, and use it directly, sadly the compiler not be able to identify this kind problem, until I run it, I notice the program will never enter one condition. finally I found the getenv system call returns char* and I compare it with a string in C++, so this will not equal forever. This reminds me a book called Algorithms + Data Structures = Programs. I must know what data structure I manipulated with. Under this promise, I will write good and correct programs. So deal with function input well is a good habit with doubt. ...

July 30, 2023 · 1 min · hengist

Default value of function

Should I set default value when write a function, and where to set? In the declaration or the implementation the answer is in the declaration, and should in header file. In case of other part uses this function and not set a default value, if set a default value in the implementation, the other file included this file can’t know what default value is, and not able to compile it. For example ...

July 27, 2023 · 1 min · hengist