From owner-freebsd-hackers Tue Feb 5 14:59:29 2002 Delivered-To: freebsd-hackers@freebsd.org Received: from wall.polstra.com (wall-gw.polstra.com [206.213.73.130]) by hub.freebsd.org (Postfix) with ESMTP id 4A06337B421 for ; Tue, 5 Feb 2002 14:59:26 -0800 (PST) Received: from vashon.polstra.com (vashon.polstra.com [206.213.73.13]) by wall.polstra.com (8.11.3/8.11.3) with ESMTP id g15MxMo55233; Tue, 5 Feb 2002 14:59:22 -0800 (PST) (envelope-from jdp@wall.polstra.com) Received: (from jdp@localhost) by vashon.polstra.com (8.11.6/8.11.0) id g15MxMv04928; Tue, 5 Feb 2002 14:59:22 -0800 (PST) (envelope-from jdp) Date: Tue, 5 Feb 2002 14:59:22 -0800 (PST) Message-Id: <200202052259.g15MxMv04928@vashon.polstra.com> To: hackers@freebsd.org From: John Polstra Cc: bakul@bitblocks.com Subject: Re: A question about timecounters In-Reply-To: <200202052242.RAA05212@renown.cnchost.com> References: <200202052242.RAA05212@renown.cnchost.com> Organization: Polstra & Co., Seattle, WA Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG In article <200202052242.RAA05212@renown.cnchost.com>, Bakul Shah wrote: > [I see that jdp has answered your question but] cdecl is your friend! > > $ cdecl > Type `help' or `?' for help > cdecl> explain volatile struct timecounter *timecounter > declare timecounter as pointer to volatile struct timecounter > cdecl> declare timecounter as volatile pointer to struct timecounter > struct timecounter * volatile timecounter Is C a great language, or what? ;-) The way I always remember it is that you read the declaration inside-out: starting with the variable name and then heading toward the outside while obeying the precedence rules. When you hit a "*", you say "pointer to"; when you hit "[]", you say "array of"; and when you hit "()" you say "function returning." For example: struct timecounter * volatile timecounter; /* "Timecounter is a volatile pointer to a struct timecounter." */ volatile struct timecounter *timecounter; /* "Timecounter is a pointer to a struct timecounter which is volatile." */ The reason for the awkward "which is" in that last one is just because C lets you get sloppy with the ordering of the outermost keywords. The pedantically correct way to declare a pointer to volatile struct is like this: struct timecounter volatile *timecounter; /* "Timecounter is a pointer to a volatile struct timecounter." */ John -- John Polstra John D. Polstra & Co., Inc. Seattle, Washington USA "Disappointment is a good sign of basic intelligence." -- Chögyam Trungpa To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message