[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] Coding style, C++ compatible code (was Re: [Qemu-devel]

From: Gerd Hoffmann
Subject: Re: [Qemu-devel] Coding style, C++ compatible code (was Re: [Qemu-devel] [PATCH 02/22] eepro100: cast a void * makes no sense)
Date: Wed, 26 Aug 2009 16:49:05 +0200
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1b3pre) Gecko/20090513 Fedora/3.0-2.3.beta2.fc11 Lightning/1.0pre Thunderbird/3.0b2


Why don't we declare structures like this: typedef struct { ... } T;?
I suggest this to be the new coding style for structure declarations
because it is shorter, C++ compatible and unambiguous.

There are quite a few cases where this will simply not work. They usually use a slightly different declaration style though:

typedef struct T T;
struct T {
  /* stuff here */

Reasons why this is used/needed:

(1) structs pointing to each other, like this:

typedef struct A A;
typedef struct B B;

struct A {
  B *b;
struct B {
  A *a;

(2) keep the struct private, let others pass around pointers
    to the struct in a typesafe way though:

header file:

typedef struct T T;
T* get_foo(args);
int do_something_with_foo(T*);

source file:

struct T {
  /* stuff here */


reply via email to

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