Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't GNOME use C99?

Looking at mutter source code and evince source code, both still use C89 style of declaring all variables at the very beginning of the function, instead of where it is first used (limited scope is good). Why don't they use C99? GNOME 3 was launch recently and mutter is quite new, so that could have been a good opportunity to switch, if the reason was compatibility with old code style.

Does that mean that contributing code to GNOME needs to be written in C89?

like image 894
eduardo Avatar asked May 20 '11 02:05

eduardo


3 Answers

The rationale can be linked to the same rationale behind Glib and GTK+:

  • No C99 comments or declarations.

Rationale: we expect GLib and GTK+ to be buildable on various compilers and C99 support is still not yet widespread.

Source: http://live.gnome.org/GTK+/BestPractices

like image 146
onteria_ Avatar answered Oct 23 '22 00:10

onteria_


Many people consider declaring variables all over the place, as opposed to at the beginning of the block, bad style. It makes it mildly more work to look for declarations, and makes it so you have to inspect the whole function to find them all. Also, for whatever reason, declarations after statements were one of the last C99 features GCC implemented, so for a long time, it was a major compatibility consideration.

like image 1
R.. GitHub STOP HELPING ICE Avatar answered Oct 23 '22 00:10

R.. GitHub STOP HELPING ICE


Speaking of scope, I guess you can still do this:

if (condition)
{
  int temporary = expression();
  trigger_side_effect(temporary);
}

In other words, each actual brace-enclosed scope can contain new variable declarations, even in C89. Many people seem surprised by this; there's no difference from this perspective between a function's top-level scope and any other scope contained therein. Variables will be visible in all scopes descending from the one that declared them.

Note that I don't know if this is supported by the GNOME style guide, but it's at least supported by C89, and a recommended technique (by me) to keep things as local as possible.

like image 2
unwind Avatar answered Oct 23 '22 00:10

unwind