Peter Krempa <pkrempa(a)redhat.com> [2017-03-06, 10:40AM +0100]:
On Mon, Mar 06, 2017 at 10:21:28 +0100, Bjoern Walk wrote:
> I personally would prefer this style:
>
> typedef struct _virHashTable {
> ...
> } virHashTable, *virHashTablePtr;
>
> This is done for example in src/conf/device_conf.h. Subjectively, it is
> much easier to read, but objectively, it is more concise and enhances
> discoverability. For example, in src/conf/domain_conf.h the typedef are
> at the beginning of the file separated from the definition of the
> struct. If I want to look up a virDomainDiskDefPtr it requires two
> jumps.
The two part declaration is necessary if you want to hide the
implementation of the struct in the .c file so that other places can't
access it directly, thus we'd either have to allow both, or the two part
can be the only one used. See src/conf/numa_conf.(c|h) for example of
the above.
Fair enough, didn't think of this. Still, maybe the fact that with the
combined declaration one can jump directly to a type outweighs the
benefits of this strict encapsulation? It just is often very annoying to
have to jump through an additional hoop and it may break some tools like
code completion. Also, a misuse of the type in a different place can
easily prevented by review.
But well, I just wanted to chip in with a discussion, at least I know
see that there is a valid use for this pattern.
--
libvir-list mailing list
libvir-list(a)redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
--
IBM Systems
Linux on z Systems & Virtualization Development
------------------------------------------------------------------------
IBM Deutschland
Schönaicher Str. 220
71032 Böblingen
Phone: +49 7031 16 1819
E-Mail: bwalk(a)de.ibm.com
------------------------------------------------------------------------
IBM Deutschland Research & Development GmbH
Vorsitzende des Aufsichtsrats: Martina Koederitz
Geschäftsführung: Dirk Wittkopp
Sitz der Gesellschaft: Böblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294