4 ms·
>The kernel is different from userspace projects - more difficult in some respects (we use a lot of very odd header files that pushes the boundary of what can b
by esgwpl 6y ago
>The kernel is different from userspace projects - more difficult in some respects (we use a lot of very odd header files that pushes the boundary of what can be called "C"), but easier in many other respects (mainly in the sense that the kernel is fairly self-contained, and then doesn't rely on other projects for the final binary).
I'm interested in what Torvalds meant by these odd header files, does anyone know?
- tambourine_man 6y agoProbably some crazy macros that the kernel code uses. You can end up having an almost dialect of C with extensive use.
- cransoon 6y ago/* * This returns a constant expressionn while determining if an argument is * a constant expression, most importantly without evaluating the argument. * Glory to Martin Uecker <Martin.Uecker@med.uni-goettingen.de> */ #define __is_constexpr(x) \ (sizeof(int) == sizeof(*(8 ? ((void *)((long)(x) * 0l)) : (int *)8)))
- PixelOfDeath 6y agoThe dark side of c is a pathway to many abilities, some considered to be unnatural
- nmfisher 6y agoJesus, can someone unravel that for me?
- Koshkin 6y agoI can try... In short, this is about how a C compiler is supposed to deduce the type of the ternary operation. So, if x is a constant expression, the compiler figures that the second operand must be NULL (because it is allowed to perform the multiplication, by 0l), whose type then is whatever the third operand says (a pointer to int). The comparison succeeds. Otherwise the compiler does not perform the multiplication, takes the type of the second operand at its “face value”, i.e. as a pointer to void, and converts the type of the third operand to it - which, of course, makes the comparison false in this case.
- esgwpl 6y agoI found a detailed explanation here: https://stackoverflow.com/a/49481218 https://stackoverflow.com/a/49481218
- ufo 6y agoSome explanation from Linus about how this trick works: https://lkml.org/lkml/2018/3/20/845 https://lkml.org/lkml/2018/3/20/845
- 120bits 6y agowow! As mainly a Java engineer. This is an alien language to me.
- joseluisq 6y agoWow! the above code is described by itself about what Torvalds means with: very odd header files that *pushes the boundary* of what can be called "C". I'm not a C dev BTW.