A
Andrey Vul
I'm creating an object that looks like this:
file: reader.h
....
typedef struct reader { /* ... */ } reader_t;
....
reader_t *reader_xopen(const char * path, void *extbuf, int buflen);
reader_t *reader_fxopen(int fd, void *extbuf, int buflen);
reader_t *reader_open(const char *path);
reader_t *reader_fopen(int fd);
....
file: reader.c
static reader_t *
init_helper(const char *path, int fd, void *buf, int buflen, int ext)
{
reader_t *rdr = malloc(sizeof(reader_t));
...
return rdr;
}
inline reader_t *
reader_xopen(const char *path, void *extbuf, int buflen) {
return init_helper(path, -1, extbuf, buflen, extbuf != NULL);
}
inline reader_t *
reader_fxopen(int fd, void *extbuf, int buflen) {
return init_helper(NULL, fd, extbuf, buflen, extbuf != NULL);
}
inline reader_t *
reader_open(const char *path) {
return init_helper(path, -1, NULL, 0, 0);
}
inline reader_t *
reader_fopen(int fd) {
return init_helper(NULL, fd, NULL, 0, 0);
}
Will the following snippet cause undefined operation?
Should I un-inline the one-line wrapper functions?
file: reader.h
....
typedef struct reader { /* ... */ } reader_t;
....
reader_t *reader_xopen(const char * path, void *extbuf, int buflen);
reader_t *reader_fxopen(int fd, void *extbuf, int buflen);
reader_t *reader_open(const char *path);
reader_t *reader_fopen(int fd);
....
file: reader.c
static reader_t *
init_helper(const char *path, int fd, void *buf, int buflen, int ext)
{
reader_t *rdr = malloc(sizeof(reader_t));
...
return rdr;
}
inline reader_t *
reader_xopen(const char *path, void *extbuf, int buflen) {
return init_helper(path, -1, extbuf, buflen, extbuf != NULL);
}
inline reader_t *
reader_fxopen(int fd, void *extbuf, int buflen) {
return init_helper(NULL, fd, extbuf, buflen, extbuf != NULL);
}
inline reader_t *
reader_open(const char *path) {
return init_helper(path, -1, NULL, 0, 0);
}
inline reader_t *
reader_fopen(int fd) {
return init_helper(NULL, fd, NULL, 0, 0);
}
Will the following snippet cause undefined operation?
Should I un-inline the one-line wrapper functions?