...
Compliant Solution (interface)
| Wiki Markup |
|---|
The managedPOSIX ^®^ stringthreads library \[[BurchButenhof 0697|AA. C References#Burch06References#Butenhof 97]\] triesdefines toan beinterface asthat consistentis asboth possible,consistent bothand internally,fits andin with established conventions from the rest Cof the standardPOSIX library. For example, all initialization functions that operate on a single instance of a {{string_m}}, but do modify the contents of the managed string, follow the pattern follow the same consistent pattern of the first argument being a pointer to the object to initialize with the subsequent arguments, if any, optionally providing additional attributes for the initialization: |
| Code Block | ||
|---|---|---|
| ||
errno_t strlen_m(const string_m s, rsize_t *size);
errno_t isnull_m(const string_m s, _Bool *nullstr);
errno_t cgetstr_m(const string_m s, char **string);
| ||
/* initialization of Pthread attribute objects */
int pthread_condattr_init(pthread_condattr_t*);
int pthread_mutexattr_init(pthread_mutexattr_t*);
int pthread_rwlockattr_init(pthread_rwlockattr_t*);
...
/* initialization of Pthread objects using attributes */
int pthread_cond_init(pthread_cond_t* restrict, const pthread_condattr_t* restrict);
int pthread_mutex_init(pthread_mutex_t* restrict, const pthread_mutexattr_t* restrict);
int pthread_rwlock_init(pthread_rwlock_t* restrict, const pthread_rwlockattr_t* restrict);
...
|
Function arguments that refer to objects that aren't modified are declared const. Since the object pointed to by the first argument is modified by the function, it is not constwhere the first argument is declared as const string_m. For functions that implement a data abstraction (see DCL12-C. Implement abstract data types using opaque types), it is reasonable to define the handle for the data abstraction as the initial parameter. Finally, initialization functions that accept a pointer to an attribute object allow it to be NULL as an indication that a reasonable default be used.
Noncompliant Code Example (behavior)
...