Re: Style convention question
- From: Mark Mielke <mark mark mielke cc>
- To: Sebastian Wilhelmi <wilhelmi ira uka de>
- Cc: Derek Simkowiak <dereks realloc net>, gtk-devel-list gnome org
- Subject: Re: Style convention question
- Date: Fri, 9 Mar 2001 12:33:33 -0500
On Fri, Mar 09, 2001 at 05:58:01PM +0100, Sebastian Wilhelmi wrote:
> > Why does Glib do this:
> > typedef struct _GFoo GFoo;
> > struct _GFoo {
> > /* [...] */
> > };
> > ...instead of the more compact
> > typedef struct {
> > /* [...] */
> > } GFoo;
> Not being the definite source for that information, I think that is because
> sometimes "GFoo*" is used without "struct _GFoo" being declared (for opaque
> structs). For the other structs it's just consistency.
The second uses an anonymously defined struct, and generates warnings
with several compilers.
struct { a, b, c } is not necessarily: struct { a, b, c }
whereas:
struct abc _is_: struct abc
A typedef can be considered more of an "alias" for most compilers.
Consider:
/* The '_' isn't strictly necessary, and the typedef can be left
* out if C++ is being used to perform the compile.
*/
#ifndef __cplusplus
typedef Object struct Object;
#endif
struct Object {
...
};
int func (Object o) {
{
...
}
...
struct Object o1;
Object o2;
struct { same_fields_as_struct_Object } o3;
func(o1); /* Legal */
func(o2); /* Legal */
func(o3); /* Illegal */
mark
--
mark mielke cc/markm ncf ca/markm nortelnetworks com __________________________
. . _ ._ . . .__ . . ._. .__ . . . .__ | Neighbourhood Coder
|\/| |_| |_| |/ |_ |\/| | |_ | |/ |_ |
| | | | | \ | \ |__ . | | .|. |__ |__ | \ |__ | Ottawa, Ontario, Canada
One ring to rule them all, one ring to find them, one ring to bring them all
and in the darkness bind them...
http://mark.mielke.cc/
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]