vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Can I declare a struct in a function's declaration section? Something like this: static void foobar(void) { struct foo { Oid foo; int bar; }; struct foo baz; baz.foo = InvalidOid; baz.bar = 42; } I tried here and GCC does not complain, with -std=c89 -pedantic. -- Alvaro Herrera http://www.CommandPrompt.com/ PostgreSQL Replication, Consulting, Custom Development, 24x7 support ---------------------------(end of broadcast)--------------------------- TIP 7: You can help support the PostgreSQL project by donating at http://www.postgresql.org/about/donate |
| |||
| Alvaro Herrera wrote: > Can I declare a struct in a function's declaration section? Something > like this: > > static void > foobar(void) > { > struct foo { > Oid foo; > int bar; > }; > > struct foo baz; > > baz.foo = InvalidOid; > baz.bar = 42; > > } > > I tried here and GCC does not complain, with -std=c89 -pedantic. Sure. -- Bruce Momjian <bruce@momjian.us> http://momjian.us EnterpriseDB http://www.enterprisedb.com + If your life is a hard drive, Christ can be your backup. + ---------------------------(end of broadcast)--------------------------- TIP 3: Have you checked our extensive FAQ? http://www.postgresql.org/docs/faq |
| |||
| Alvaro Herrera wrote: > Can I declare a struct in a function's declaration section? Something > like this: > > static void > foobar(void) > { > struct foo { > Oid foo; > int bar; > }; > > struct foo baz; > > baz.foo = InvalidOid; > baz.bar = 42; > > } > > I tried here and GCC does not complain, with -std=c89 -pedantic. > It works fine with Sun Studio 11. Zdenek ---------------------------(end of broadcast)--------------------------- TIP 1: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to majordomo@postgresql.org so that your message can get through to the mailing list cleanly |
| |||
| "Tom Lane" <tgl@sss.pgh.pa.us> writes: > Zdenek Kotala <Zdenek.Kotala@Sun.COM> writes: >> Alvaro Herrera wrote: >>> Can I declare a struct in a function's declaration section? > >> It works fine with Sun Studio 11. > > AFAICT it's required by the original K&R C book. IIRC there's something odd about the scope of the declared struct label. Something like it previously extended to the end of the file but post-ANSI was limited to the scope it's declared in (including very limited scopes where it would be useless such as in function parameters). -- Gregory Stark EnterpriseDB http://www.enterprisedb.com ---------------------------(end of broadcast)--------------------------- TIP 2: Don't 'kill -9' the postmaster |
| |||
| Zdenek Kotala <Zdenek.Kotala@Sun.COM> writes: > Alvaro Herrera wrote: >> Can I declare a struct in a function's declaration section? > It works fine with Sun Studio 11. AFAICT it's required by the original K&R C book. regards, tom lane ---------------------------(end of broadcast)--------------------------- TIP 7: You can help support the PostgreSQL project by donating at http://www.postgresql.org/about/donate |
| |||
| Gregory Stark wrote: > "Tom Lane" <tgl@sss.pgh.pa.us> writes: > > > Zdenek Kotala <Zdenek.Kotala@Sun.COM> writes: > >> Alvaro Herrera wrote: > >>> Can I declare a struct in a function's declaration section? > > > >> It works fine with Sun Studio 11. > > > > AFAICT it's required by the original K&R C book. > > IIRC there's something odd about the scope of the declared struct label. > > Something like it previously extended to the end of the file but post-ANSI was > limited to the scope it's declared in (including very limited scopes where it > would be useless such as in function parameters). Hmm, thanks everybody. I was just going to say "bummer!" because I needed to build a qsort comparator for these, but then I realized that it's better if I keep worker and launcher database structs separate -- the only field they use in common is the Oid anyway. -- Alvaro Herrera http://www.CommandPrompt.com/ PostgreSQL Replication, Consulting, Custom Development, 24x7 support ---------------------------(end of broadcast)--------------------------- TIP 6: explain analyze is your friend |
| ||||
| Gregory Stark <stark@enterprisedb.com> writes: > IIRC there's something odd about the scope of the declared struct label. > Something like it previously extended to the end of the file but post-ANSI was > limited to the scope it's declared in (including very limited scopes where it > would be useless such as in function parameters). I think you might be thinking of the use of a previously unreferenced "struct foo" in a function declaration's parameter list, which is something that did change (and so gcc warns about it). But within a block is not that case. regards, tom lane ---------------------------(end of broadcast)--------------------------- TIP 2: Don't 'kill -9' the postmaster |