Is it possible for C preprocessor macros to contain preprocessor directives?

The Boost Preprocessor (which works for C as well as C++, even though Boost as a whole is a C++ library) library can help with this kind of task. Instead of using an #ifdef within a macro (which isn’t permitted), it helps you include a file multiple times, with different macros defined each time, so … Read more

Is it possible to declare variables procedurally using Rust macros?

Yes however this is only available as a nightly-only experimental API which may be removed. You can pass arbitrary identifier into a macro and yes, you can concatenate identifiers into a new identifier using concat_idents!() macro: #![feature(concat_idents)] macro_rules! test { ($x:ident) => ({ let z = concat_idents!(hello_, $x); z(); }) } fn hello_world() { } … Read more

Auto release of stack variables in C

You could use the cleanup variable attribute in GCC. Please take a look at this: http://echorand.me/site/notes/articles/c_cleanup/cleanup_attribute_c.html Sample code: #include <stdio.h> #include <stdlib.h> void free_memory(void **ptr) { printf(“Free memory: %p\n”, *ptr); free(*ptr); } int main(void) { // Define variable and allocate 1 byte, the memory will be free at // the end of the scope by … Read more

How big can a malloc be in C?

Observations Assuming a typical allocator, such as the one glibc uses, there are some observations: Whether or not the memory is actually used, the region must be reserved contiguously in virtual memory. The largest free contiguous regions depends on the memory usage of existing memory regions, and the availability of those regions to malloc. The … Read more

Easy way to convert exec sp_executesql to a normal query?

I spent a little time making an simple script that did this for me. It’s a WIP, but I stuck a (very ugly) webpage in front of it and it’s now hosted here if you want to try it: http://execsqlformat.herokuapp.com/ Sample input: exec sp_executesql N’SELECT * FROM AdventureWorks.HumanResources.Employee WHERE ManagerID = @level’, N’@level tinyint’, @level … Read more