Archive for November, 2011

C99: casting to variable-length arrays

Wednesday, November 30th, 2011

C99 understands variable-length arrays. They look something like this:

int d1, d2, d3, d4;
// runtime-assign those variables
int vla[d1][d2][d3][d3];

Now the question is, how to properly cast a pointer to this type when passing it to a function that accepts such a type in a way that makes the compiler happy? The syntax is somewhat unusual:

void func(int d1, int d2, int d3, int d4, int vla[d1][d2][d3][d4]){}
// ...
int * x = malloc();
func(d1, d2, d3, d4, (int (*)[(int)(d2)][(int)(d3)][(int)(d4)])x);

Tested with gcc 4.6.1 and the –std=c99 compiler option. I could not find information about this anywhere on the web so I hope this will help others who wonder how it should be done.

Mozilla Thunderbird and Flowed Format

Wednesday, November 2nd, 2011

I like my e-mails to look a particular way. I send plain-text only e-mails with line wrapping at about 80 characters. This way I feel I can control to some degree what the e-mail will look like at the receivers end. And I want my e-mails to look like that even when I’m quoting someone.

Up until now I hated to use Thunderbird because it did not allow me to send e-mails like that. Since gmail looks ugly as hell now I came back to Thunderbird and set out to solve this issue once and for all. I searched for “thunderbird plain text wrap” and whatnot. A smart fellow on a forum had the answer:

There are two hidden preference settings which one can access through Edit > Preference > Advanced > General > Config Editor button:

  • mailnews.display.disable_format_flowed_support must be set to true to avoid rewarpping of messages received for which the sender allows flowed formatting
  • mailnews.send_plaintext_flowed must be set to “false” to avoid sending flowed format e-mails

The problem seems to be something called “flowed format” but I’m too ignorant to go into the details of what it does, what it means and why I would want it. I’m just happy the e-mails my Thunderbird sends look the way I want them to look. Finally. Thank you rsx11m!