How can I simulate macros in JavaScript?
You could use parenscript. That’ll give you macros for Javascript.
You could use parenscript. That’ll give you macros for Javascript.
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
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
The preprocessor is not a text processor, it works on the level of tokens. In your code, after the define, every occurence of the token X would be replaced by the token 10. However, there is not token X in the rest of your code. 1e-X is syntactically invalid and cannot be turned into a … Read more
#define STRINGIFY2(X) #X #define STRINGIFY(X) STRINGIFY2(X) #define A 2 Then STRINGIFY(A) will give you “2”. You can concatenate it with other string literals by putting them side by side. “I have the number ” STRINGIFY(A) “.” gives you “I have the number 2.”.
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
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
You can easily record a macro to do it. First insert 1. at the start of the first line (there are a couple of spaces after the 1. but you can’t see them). Go to the start of the second line and go into record mode with qa. Press the following key sequence: i # … Read more
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