[Freeciv-Dev] Re: TODO
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
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...
- [Freeciv-Dev] Re: TODO, (continued)
- [Freeciv-Dev] Re: TODO, Raimar Falke, 2000/09/22
- [Freeciv-Dev] Re: TODO, Jules Bean, 2000/09/22
- [Freeciv-Dev] Re: TODO, Daniel Sjölie, 2000/09/22
- [Freeciv-Dev] Re: TODO, Jeff Mallatt, 2000/09/22
- [Freeciv-Dev] Re: TODO, Jules Bean, 2000/09/22
- [Freeciv-Dev] Re: TODO, Jeff Mallatt, 2000/09/22
- [Freeciv-Dev] Re: TODO, Raimar Falke, 2000/09/22
- [Freeciv-Dev] Re: TODO, Daniel Sjölie, 2000/09/22
- [Freeciv-Dev] Re: TODO, Gaute B Strokkenes, 2000/09/22
- [Freeciv-Dev] Re: TODO, Greg Wooledge, 2000/09/22
- [Freeciv-Dev] Re: TODO,
Gaute B Strokkenes <=
- [Freeciv-Dev] Re: TODO, Erik Sigra, 2000/09/22
- [Freeciv-Dev] Re: -ansi -pedantic, was Re: TODO, David Pfitzner, 2000/09/22
[Freeciv-Dev] Re: TODO, David Pfitzner, 2000/09/24
|
|