Skip to content

Commit

Permalink
provide a FBUF_STATIC_INITIALIZER_POINTER() macro
Browse files Browse the repository at this point in the history
to simplify (and speedup) initialization of a static fbuf structure.

This is handy when you have a preallocated structure which contains an fbuf_t member
(not a pointer) and we want to set custom parameters without having to call multiple functions to do that
(and obviously FBUF_STATIC_INITIALIZER can't be used because we are not in a declaration statement)
  • Loading branch information
Andrea Guzzo committed Sep 16, 2014
1 parent 3065036 commit abea155
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/fbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ extern "C" {
#define FBUF_STATIC_INITIALIZER_PARAMS(__maxlen, __minlen, __fastgrow, __slowgrow) \
{ 0, NULL, 0, (__maxlen), (__minlen), (__fastgrow), (__slowgrow), 0, 0 }

#define FBUF_STATIC_INITIALIZER_POINTER(__fbuf, __maxlen, __minlen, __fastgrow, __slowgrow) \
{ \
(__fbuf)->id = 0; \
(__fbuf)->data = NULL; \
(__fbuf)->maxlen = (__maxlen); \
(__fbuf)->minlen = (__minlen); \
(__fbuf)->fastgrowsize = (__fastgrow); \
(__fbuf)->slowgrowsize = (__slowgrow); \
(__fbuf)->used = 0; \
(__fbuf)->skip = 0; \
}

typedef struct __fbuf {
unsigned int id; //!< unique ID for the buffer for reference
char *data; //!< buffer. the caller should never access it directly but use
Expand Down

0 comments on commit abea155

Please sign in to comment.