From owner-freebsd-current Mon Oct 21 01:59:13 1996 Return-Path: owner-current Received: (from root@localhost) by freefall.freebsd.org (8.7.5/8.7.3) id BAA02461 for current-outgoing; Mon, 21 Oct 1996 01:59:13 -0700 (PDT) Received: from parkplace.cet.co.jp (parkplace.cet.co.jp [202.32.64.1]) by freefall.freebsd.org (8.7.5/8.7.3) with ESMTP id BAA02456 for ; Mon, 21 Oct 1996 01:59:09 -0700 (PDT) Received: from localhost (michaelh@localhost) by parkplace.cet.co.jp (8.8.0/CET-v2.1) with SMTP id IAA23820; Mon, 21 Oct 1996 08:58:55 GMT Date: Mon, 21 Oct 1996 17:58:55 +0900 (JST) From: Michael Hancock To: John Polstra cc: current@freebsd.org Subject: Re: In-Reply-To: <199610210237.TAA05813@austin.polstra.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-current@freebsd.org X-Loop: FreeBSD.org Precedence: bulk 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