Sunday, September 7, 2008

C magics

Recently Linus Torvalds has sent a patch for the e1000 driver. Looking at it, I'm not sure if I should be amazed by the talent of Linus, or by the fact that even after 10 years of using C there are still constructs which I don't know.

It does things like:

- struct e1000_opt_list speed_list[] = {
:
+ static const struct e1000_opt_list speed_list[] = {

and:

- struct e1000_option opt = {
:
+ opt = (struct e1000_option) {


Not only I didn't even know this last construct was possible, but Linus reports that overall his patch reduces the stack usage from 1152 bytes to 192 bytes (the total stack is 4K)! Ahhh... how much more to learn about C?