Monday, May 24, 2010

#iso c/c++: runtime and static assertion for gcc 4.4.0+

re: axonlib
we've made some very good progress on the library. v.0.1.0 is about to be released soon. we now have image transparency, scalable images, a lot of widgets, a custom set of stdlib routines for string and memory, a rather fragmenting but fast custom memory allocator and other. also we are now not using heavy c++ types such as 'vector' any more, while 'iostream' is only used for debug builds.

i have made a little page to write some articles on programming methods, optimization techniques, assembler trick and other things i've learned over the years or just recently.

as far as programming goes i may be focusing more on assembler and c over c++ and higher level languages.

the first article that is done now is about assertion:

the original methods are part of axonlib but i release these to the public (under a fairly permissive license) as _none_ of the examples in the internet that i've tried out of interest worked properly and gave errors / warnings for either c or c++ code with the gcc compiler.

[edit] actually the following seems to work as well with not much overhead:

#define STATIC_ASSERT(e) switch(0) { case 0: case (e): ; }
resulting in two errors:
file:line: error: duplicate case value
file:line: error: previously used here

..and is a portable solution, but not very useful because the macro will expand to a switch call but in the same time (e) has to be a constant.