Skip to content

Commit

Permalink
Add STATIC_ASSERT() macro and use it
Browse files Browse the repository at this point in the history
  • Loading branch information
kwolekr committed Oct 28, 2015
1 parent c56d7fe commit 688556a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/basicmacros.h
Expand Up @@ -38,4 +38,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
C(const C &); \
C &operator=(const C &)

// Fail compilation if condition expr is not met.
// Note that 'msg' must follow the format of a valid identifier, e.g.
// STATIC_ASSERT(sizeof(foobar_t) == 40), foobar_t_is_wrong_size);

This comment has been minimized.

Copy link
@PilzAdam

PilzAdam Oct 30, 2015

Contributor

Unbalanced parenthesis.

#define STATIC_ASSERT(expr, msg) typedef char msg[!!(expr) * 2 - 1]

#endif
6 changes: 4 additions & 2 deletions src/log.cpp
Expand Up @@ -135,7 +135,8 @@ class AndroidSystemLogOutput : public ICombinedLogOutput {
}
void logRaw(LogLevel lev, const std::string &line)
{
assert(ARRLEN(g_level_to_android) == LL_MAX);
STATIC_ASSERT(ARRLEN(g_level_to_android) == LL_MAX,
mismatch_between_android_and_internal_loglevels);
__android_log_print(g_level_to_android[lev],
PROJECT_NAME_C, "%s", line.c_str());
}
Expand Down Expand Up @@ -228,7 +229,8 @@ const std::string Logger::getLevelLabel(LogLevel lev)
"VERBOSE",
};
assert(lev < LL_MAX && lev >= 0);
assert(ARRLEN(names) == LL_MAX);
STATIC_ASSERT(ARRLEN(names) == LL_MAX,
mismatch_between_loglevel_names_and_enum);
return names[lev];
}

Expand Down

1 comment on commit 688556a

@ShadowNinja
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would also be useful for the irrlicht-to-minetest log level list.

Please sign in to comment.