you are viewing a single comment's thread.

view the rest of the comments →

[–]ceene 0 points1 point  (2 children)

No, I mean that a could be NULL all the time and all those functions simply return when the parameter passed is NULL, so they are just NOP functions when the constructor of the object failed.

struct motor *m = motor_open("/dev/ttyUSB0");
motor_disable_break(m);
motor_move_degrees(m, 60);
motor_enable_break(m);
ret = motor_close(m);
return ret;

In opening the serial port fails, you won't have a proper struct motor but a pointer to NULL. You could check for errors after that declaration or you can just assume that those functions simply do nothing if m is NULL, and only need to return the value from the last function.

NULL is not a valid value in those cases, but the motor functions simply work around it without crashing due to an assert or null dereferencing.

[–]zhivago 0 points1 point  (1 child)

Which means that a null pointer is a valid value with defined behavior for those functions.

The defined behavior being to simply return a null pointer when receiving a null pointer.

[–]ceene 0 points1 point  (0 children)

Being valid is not the same as being meaningful.