Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 5 Feb 2002 14:59:22 -0800 (PST)
From:      John Polstra <jdp@polstra.com>
To:        hackers@freebsd.org
Cc:        bakul@bitblocks.com
Subject:   Re: A question about timecounters 
Message-ID:  <200202052259.g15MxMv04928@vashon.polstra.com>
In-Reply-To: <200202052242.RAA05212@renown.cnchost.com>
References:  <200202052242.RAA05212@renown.cnchost.com>

next in thread | previous in thread | raw e-mail | index | archive | help
In article <200202052242.RAA05212@renown.cnchost.com>,
Bakul Shah  <bakul@bitblocks.com> 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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200202052259.g15MxMv04928>