On Mon, Apr 10, 2006 at 12:36:22AM -0400, Zach wrote:
> On 4/9/06, James Cameron <quozl at us.netrek.org> wrote:
> >
> > GCC 2.6 isn't supported by this code.  Use a more recent compiler.  The
> > code as it stands relies on inline declarations, a feature I'm told of
> > ANSI C99.
> 
> http://en.wikipedia.org/wiki/Inline_function

Erm, no, not inline functions, but inline declarations.  Perhaps I'm not
using a term with a shared semantic.

See http://en.wikipedia.org/wiki/Declaration_%28computer_science%29

Example inline declarations from tools/players.c function comment are
the variables file, text, and res:

static char *comment() {
  char name[MAXPATH];
  snprintf(name, MAXPATH, "%s/%s", SYSCONFDIR, "comment");
  FILE *file = fopen(name, "r");
  if (file == NULL) return "";
  static char text[80];
  char *res = fgets(text, 80, file);
  fclose(file);
  if (res == NULL) return "";
  res[strlen(res)-1] = '\0';
  return res;
}

To write this with declarations at the top of the function would remove
the use of inline declarations:

static char *comment() {
  char name[MAXPATH];
  FILE *file;
  static char text[80], *res;

  snprintf(name, MAXPATH, "%s/%s", SYSCONFDIR, "comment");
  file = fopen(name, "r");
  if (file == NULL) return "";
  res = fgets(text, 80, file);
  fclose(file);
  if (res == NULL) return "";
  res[strlen(res)-1] = '\0';
  return res;
}

Which is more correct is a matter of style and code comprehension.  I've
not had any comments on this yet.

-- 
James Cameron    mailto:quozl at us.netrek.org     http://quozl.netrek.org/