Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 21 Oct 1996 17:58:55 +0900 (JST)
From:      Michael Hancock <michaelh@cet.co.jp>
To:        John Polstra <jdp@polstra.com>
Cc:        current@freebsd.org
Subject:   Re: <sys/queue.h> 
Message-ID:  <Pine.SV4.3.93.961021174341.23727A-100000@parkplace.cet.co.jp>
In-Reply-To: <199610210237.TAA05813@austin.polstra.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, 20 Oct 1996, John Polstra wrote:

> > It's questionable to define a typedef just to save typing the word struct.
> 
> True, but that's not the point.  The point is, at a certain level,
> a type is a type is a type.  You shouldn't have to know whether
> it's represented as a struct or as a union or as an array.  By
> using a typedef you enforce not knowing the details of the
> representation, making it easier to change that representation in
> the future without having to change a bunch of code.  The more
> opaque a type is, the easier it is to change it later, if you need
> to.
> 
> It isn't about saving typing, just as "dev_t" isn't about avoiding
> typing "unsigned int", and "jmp_buf" isn't about avoiding typing

When you typedef a scalar, it's more for portability.

> "struct { int _jb[9]; } foo[1];"  It's about information hiding.

In the case of a simple struct you don't want to use typedefs.  When you
start mixing in arrays, structs, pointers, and functions you do want to
use typedefs for information hiding as you say. 

Not using typedefs for simple structs is just a good habit to have when
programming in C.  C just has too many ambiguities.

typedef struct foo {int foo} foo;
	struct foo x;
	       foo y;
	       foo foo;

What is foo?

If you're using a simple struct, the details of the struct may change but
it's unlikely that the struct will become a scalar.  You still have
information hiding.

Regards,


Mike Hancock




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.SV4.3.93.961021174341.23727A-100000>