4 ms·
In C's grammar you would need to wrap the {} as ({}) in order to get into a block expression scope from an argument list.
by akira2501 2y ago
In C's grammar you would need to wrap the {} as ({}) in order to get into a block expression scope from an argument list.
- kazinator 2y agoThat's GNU C, not standard C. Standard C has no such feature as blocks being expressions. Compound literals are grotesque. The braces have to be proceeded by cast syntax indicating the type. It could be subject to inference. Maybe the current draft has something.
- danhau 2y agoI actually find compound literals quite pleasing, visually. Parentheses, brackets and braces I find can help a lot in guiding your eyes though code. They make it more „regular“, or lessen the „entropy“ (physicists, please don‘t stone me). For this reason I‘ve come to dislike Rust’s braceless if-syntax, after being a die-hard fan. With parentheses it just reads better.
- flohofwoe 2y agoC99 has compound literals which allows you to call functions that take struct values or pointers to structs like this: my_func((my_type){ .x = 1, .y = 2 }); my_func(&(my_type){ .x = 1, .y = 2 });