This forces the use of a semicolon after INIT() and makes existing ones,
which was the case for basically all instances, necessary so e.g.
sonarcloud won't complain about an empty statement after every one of
them.
By evaluating to the allocated object, it would theoretically also allow
constructs like this:
struct_t *this;
return INIT(this,
.a = x,
.b = y,
);
or this:
array_insert(a, ARRAY_TAIL, INIT(this,
.a = x,
.b = y,
));
{
INIT(config,
.scheme = scheme,
- )
+ );
array_insert(selected, ARRAY_TAIL, config);
}
}
/**
* Object allocation/initialization macro, using designated initializer.
*/
-#define INIT(this, ...) { (this) = malloc(sizeof(*(this))); \
- *(this) = (typeof(*(this))){ __VA_ARGS__ }; }
+#define INIT(this, ...) ({ (this) = malloc(sizeof(*(this))); \
+ *(this) = (typeof(*(this))){ __VA_ARGS__ }; (this); })
/**
* Aligning version of INIT().
.package = strndup(package.ptr, package.len),
.version = strndup(version.ptr, version.len),
.old_version = strndup(old_version.ptr, old_version.len),
- )
+ );
this->sw_id = info->create_sw_id(info, this->package, this->version);
if (old_version.len)