I mean, I get it, these are all things which can be used to very easily cause chaos and shoot yourself in the foot. I look at code that I've written, though, and see so many challenges to writing the same thing in Rust.
I spend 99% of my time in embedded Linux or bare metal, though, so maybe my view point is a bit skewed.
There seem to be very few GUI libraries which can be used in Rust as well. I'll keep checking https://areweguiyet.com/
Like if you're doing #define PI 3.14159 you're asking to get chirped in code review.
#define PI 3.1415927410125732421875
that is the float closest to pi or that there is the GNU extension USE_FUNKY_DEFINES-something with M_PI for cmath. (I know you meant constexpr:ions).(It took me a while to write back to you because I am busy writing bare-metal embedded Rust, btw. Including using some macros!)
Is that not pretty much what Rust's procedural macros are? [0]
Except for the fact that they do not allow emitting invalid token streams (which is something you don't want anyways), it can do any arbitrary manipulation of source code, but in a way that is integrated with the compiler and less prone to breaking the program.
[0] https://doc.rust-lang.org/reference/procedural-macros.html
cpp_call! { fn foo() { ... } }
or #[cpp_call] fn foo() { ... }
The former can be written even with a macro_rules macro. Regardless, both macros have to work by parsing the whole input tokentree `fn foo ( ) { ... }` and emitting it back with an `unsafe` prepended. The macro invocation cannot expand to just `unsafe`.Textual substitution is less rigorous. It tells the compiler to replace a string with another, wherever it is seen. There's no restriction that it must be valid token input to be replaced or that it needs to be an explicit usage of the macro.
Reminds me of some of stringification abused in the Linux kernel. What looks like a function call passing the literal text param1## as an argument, where it would then trigger a different stringification in a subsequent preprocessor pass that prepended ##foo to the passed argument.
macro_rules! cpp_call {
($($tt:tt)*) => {
unsafe { $($tt)* }
}
}
Yeah, not pretty, but it works :PSeriously though, maybe comment annotation would be better than abusing the macros like that. I though there was a more direct cpp way. (Edit: As in the c preprocessor, not C++.)