I’m trying to create an API that is easy to use correctly and hard to use incorrectly.
Imagine you had a function "bool MyObject_SetLocalDateTime(MyObject *pMyObject, params...)" which allows client to set date and time in YYYY MM DD HH MM SS format:
MyObject *pMyObject = MyObject_Create();
...
MyObject_SetLocalDateTime(pMyObject, params...);
...
MyObject_Destroy(&pMyObject);
What would be a good interface for the function? I’d appreciate any tips on how to make interfaces easy to use correctly and hard to use incorrectly in ANSI C (not in C++).
Why wouldn’t you simply use
time_tand/orstruct tm?Something like the following would do just fine:
or