qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2] HACKING: Document 'struct' keyword usage
@ 2019-08-12 23:46 Eduardo Habkost
  2019-08-13  6:44 ` Thomas Huth
  0 siblings, 1 reply; 3+ messages in thread
From: Eduardo Habkost @ 2019-08-12 23:46 UTC (permalink / raw)
  To: qemu-devel
  Cc: Peter Maydell, Thomas Huth, Markus Armbruster, Paolo Bonzini,
	Aleksandar Markovic, Richard Henderson

Sometimes we use the 'struct' keyword in headers to help us
reduce dependencies between header files.  Document that
practice.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
Changes v1 -> v2:
* Use paragraphs written by Paolo Bonzini at
  https://www.mail-archive.com/qemu-devel@nongnu.org/msg586214.html
* Fix typos spotted by Thomas Huth
---
 HACKING | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/HACKING b/HACKING
index 0fc3e0fc04..035276e668 100644
--- a/HACKING
+++ b/HACKING
@@ -100,7 +100,19 @@ pointer, you're guaranteed that it is used to modify the storage
 it points to, or it is aliased to another pointer that is.
 
 2.3. Typedefs
-Typedefs are used to eliminate the redundant 'struct' keyword.
+
+Typedefs are used to eliminate the redundant 'struct' keyword, since type
+names have a different style than other identifiers ("CamelCase" versus
+"snake_case").  Each struct should have a CamelCase name and a
+corresponding typedef.
+
+Since certain C compilers choke on duplicated typedefs, you should avoid
+them and declare a typedef only in one header file.  For common types,
+you can use "include/qemu/typedefs.h" for example.  However, as a matter
+of convenience it is also perfectly fine to use forward struct
+definitions instead of typedefs in headers and function prototypes; this
+avoids problems with duplicated typedefs and reduces the need to include
+headers from other headers.
 
 2.4. Reserved namespaces in C and POSIX
 Underscore capital, double underscore, and underscore 't' suffixes should be
-- 
2.21.0



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH v2] HACKING: Document 'struct' keyword usage
  2019-08-12 23:46 [Qemu-devel] [PATCH v2] HACKING: Document 'struct' keyword usage Eduardo Habkost
@ 2019-08-13  6:44 ` Thomas Huth
  2019-08-13  7:59   ` Paolo Bonzini
  0 siblings, 1 reply; 3+ messages in thread
From: Thomas Huth @ 2019-08-13  6:44 UTC (permalink / raw)
  To: Eduardo Habkost, qemu-devel
  Cc: Peter Maydell, Markus Armbruster, Paolo Bonzini,
	Aleksandar Markovic, Richard Henderson

On 8/13/19 1:46 AM, Eduardo Habkost wrote:
> Sometimes we use the 'struct' keyword in headers to help us
> reduce dependencies between header files.  Document that
> practice.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
> ---
> Changes v1 -> v2:
> * Use paragraphs written by Paolo Bonzini at
>   https://www.mail-archive.com/qemu-devel@nongnu.org/msg586214.html
> * Fix typos spotted by Thomas Huth
> ---
>  HACKING | 14 +++++++++++++-
>  1 file changed, 13 insertions(+), 1 deletion(-)
> 
> diff --git a/HACKING b/HACKING
> index 0fc3e0fc04..035276e668 100644
> --- a/HACKING
> +++ b/HACKING
> @@ -100,7 +100,19 @@ pointer, you're guaranteed that it is used to modify the storage
>  it points to, or it is aliased to another pointer that is.
>  
>  2.3. Typedefs
> -Typedefs are used to eliminate the redundant 'struct' keyword.
> +
> +Typedefs are used to eliminate the redundant 'struct' keyword, since type
> +names have a different style than other identifiers ("CamelCase" versus
> +"snake_case").  Each struct should have a CamelCase name and a

Maybe s/Each struct/Each global struct/ ? Or "non-local" or something
similar? Sometimes, you also define a struct just within a function, and
in that case we don't require the typedef, do we?

> +corresponding typedef.
> +
> +Since certain C compilers choke on duplicated typedefs, you should avoid
> +them and declare a typedef only in one header file.  For common types,
> +you can use "include/qemu/typedefs.h" for example.  However, as a matter
> +of convenience it is also perfectly fine to use forward struct
> +definitions instead of typedefs in headers and function prototypes; this
> +avoids problems with duplicated typedefs and reduces the need to include
> +headers from other headers.

Reviewed-by: Thomas Huth <thuth@redhat.com>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PATCH v2] HACKING: Document 'struct' keyword usage
  2019-08-13  6:44 ` Thomas Huth
@ 2019-08-13  7:59   ` Paolo Bonzini
  0 siblings, 0 replies; 3+ messages in thread
From: Paolo Bonzini @ 2019-08-13  7:59 UTC (permalink / raw)
  To: Thomas Huth, Eduardo Habkost, qemu-devel
  Cc: Peter Maydell, Markus Armbruster, Aleksandar Markovic, Richard Henderson

On 13/08/19 08:44, Thomas Huth wrote:
> Maybe s/Each struct/Each global struct/ ? Or "non-local" or something
> similar? Sometimes, you also define a struct just within a function, and
> in that case we don't require the typedef, do we?

I changed it to "each named struct" and queued.

Thanks,

Paolo


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-08-13  8:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-12 23:46 [Qemu-devel] [PATCH v2] HACKING: Document 'struct' keyword usage Eduardo Habkost
2019-08-13  6:44 ` Thomas Huth
2019-08-13  7:59   ` Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).