Really not the same thing. Compile time asserts allow you to check any compile time value. For instance say you were writing OpenGL code and your struct needs to have a size that is a multiple of 16 bytes. In D that's easy:
static assert(sizeof(Data) % 16 == 0);#define ASSERT_BUILD(x) \ do { char array[(x) ? 1 : -1]; (void)array; } while(0)
static char foo[10]; ASSERT_BUILD(sizeof(foo) >= 10);
A common strategy is to use a self-describing variable name like `static_assertion_failed`.
char * i = malloc(1);
ASSERT_BUILD(i);
That just silently compiles and runs without triggering any failure. Whats worse is you can never be sure whether your assert is passing or the compiler decided not to run it. #define ASSERT_BUILD(x) extern int STATIC_ASSERT_FAILED[(x)?1:-1]The use of scope(exit) is actually very useful because, for example( short of using RAII) how many times do we all forget to free or close a file. Programmers make mistakes, but if you give them the tools to not fuck up as idiomatic parts of the language: They will use them.
That's not strictly true. For example, complex object assignment _might_ be turned into a function call by the compiler.