* Rasmus Villemoes: > This is something I've sometimes found myself wishing was supported. The > idea being that one can say > > unsigned a[] = { [0] = 1, [1] = 3, [0] |= 4, ...} > > which would end up initializing a[0] to 5. As a somewhat realistic > example, suppose one is trying to build a bitmap at compile time, but > the bits to set are not really known in the sense that one can group > those belonging to each index in a usual | expression. Something like > > #define _(e) [e / 8] |= 1 << (e % 8) > const u8 error_bitmap[] = { _(EINVAL), _(ENAMETOOLONG), _(EBUSY), ... }
I think it wouldn't be too hard to extend std::bitset with more compile-time operations to support this, if that's what you need. > Writing a small program to generate such a table as part of the build is > not practical in a cross-compile setting (because the constants may only > really be known to the cross-compiler, e.g. the errno values above). This is not a problem if you use GCC anyway because you can use inline assembly quite reliably to extract arbitrary compile-time constants. Search for gen-as-const-headers in the glibc sources for an example.