Complete.Org: Mailing Lists: Archives: freeciv-dev: September 2000:
[Freeciv-Dev] Re: TODO
Home

[Freeciv-Dev] Re: TODO

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: Greg Wooledge <wooledge@xxxxxxxxxxx>
Cc: Jules Bean <jules@xxxxxxxxxxxxxxxxxxxxxxxxx>, Erik Sigra <freeciv@xxxxxxx>, freeciv-dev@xxxxxxxxxxx
Subject: [Freeciv-Dev] Re: TODO
From: Gaute B Strokkenes <gs234@xxxxxxxxx>
Date: 22 Sep 2000 14:05:55 +0200

Greg Wooledge <wooledge@xxxxxxxxxxx> writes:

> Jules Bean (jules@xxxxxxxxxxxxxxxxxxxxxxxxx) wrote:
> 
> > 'on-the-fly' struct creation is not possible.
> > 
> > Instead use a 'constructor' function
> > 
> > struct locus make_locus(int x,int y) {
> >   struct locus l;
> >   l.x=x; l.y=y;
> >   return l;
> > }
> 
> jekyll:~$ cat foo.c
> #include <stdio.h>
> struct foo {
>         int x;
>         int y;
> };
> int main(void) {
>         struct foo bar = { 1, 2 };
>         printf ("%d\n", bar.x + bar.y);
>         return 0;
> }
> jekyll:~$ gcc -O -g -Wall -ansi -pedantic -o foo foo.c
> jekyll:~$ ./foo
> 3

I'm not sure what your example proves.  "struct foo bar = { 1, 2 }" is
an initialiser, which is not the same as an anonymous struct, which is
what was being discussed.

The following won't work:

--8<--
#include <stdio.h>

struct foo {
  int fu;
  int bar;
};

int main()
{
  struct foo fred;

  fred = { 1, 2}; /* This won't work. */
  return 0;
}
--8<--

If you change the assignment to
    fred = ((struct foo) { 1, 2 })
this will work in GCC.

If you're really interested, look at the node called "Constructor
Expressions" under "C extenstions" in the GCC manual.

-- 
Big Gaute (not to be confused with LG)
TAILFINS!!  ...click...



[Prev in Thread] Current Thread [Next in Thread]