Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Complicated Declarations

7 views
Skip to first unread message

paolor...@gmail.com

unread,
Apr 30, 2009, 11:35:49 PM4/30/09
to
As a new C learner, I'm coming up against the 'complicated
declarations' problem i.e. identifying what certain declarations mean.
So, reading K&R 2nd edition, I came across Section 5.12 Complicated
Declarations, and thought that the dcl program and its associated
functions were just what I needed i.e. type 'dcl <declarator>' and a
word description would pop out. So I have typed in and compiled all
the code shown (dcl, dirdcl, gettoken etc. as shown on pp. 122-126)
and called the file dcl.c

Of course, I can't just type 'dcl <declarator>' as the code as shown
doesn't allow for parsing an argument - none of the functions takes
any parameters and my C isn't yet up to modifying the code to allow
that.

Would any of the C gurus out there be able illustrate how this might
be done because I think this program is potentially a great learning
tool?

TIA

Ike Naar

unread,
May 1, 2009, 2:56:52 AM5/1/09
to
In article <4d7228c7-549b-4d0e...@z23g2000prd.googlegroups.com>,

Is it the same dcl program as the one from this URL ?

http://www.java-samples.com/showtutorial.php?tutorialid=543

That program reads from standard input.
Just type ``dcl'' without arguments at the command line, and then,
while the program is running, type the declarations you want to have
explained, one per line.

Richard Heathfield

unread,
May 1, 2009, 3:09:27 AM5/1/09
to
Ike Naar said:

<snip>


>>
>>Of course, I can't just type 'dcl <declarator>' as the code as
>>shown doesn't allow for parsing an argument - none of the
>>functions takes any parameters and my C isn't yet up to modifying
>>the code to allow that.
>>
>>Would any of the C gurus out there be able illustrate how this
>>might be done because I think this program is potentially a great
>>learning tool?
>
> Is it the same dcl program as the one from this URL ?
>
> http://www.java-samples.com/showtutorial.php?tutorialid=543
>
> That program reads from standard input.
> Just type ``dcl'' without arguments at the command line, and then,
> while the program is running, type the declarations you want to
> have explained, one per line.

I think he's asking about how to modify it so that it /does/ take
arguments at the command line - argc, argv and all that. I took a
quick look - the high level stuff is simple enough, but I don't
have the time right now to write a string-chomping version of
gettoken().

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999

paolor...@gmail.com

unread,
May 1, 2009, 3:32:52 AM5/1/09
to
On May 1, 4:56 pm, i...@localhost.claranet.nl (Ike Naar) wrote:
> In article <4d7228c7-549b-4d0e-a007-ae746034c...@z23g2000prd.googlegroups.com>,

Ike: that's the one. I didn't realise that you had to have the program
running to get explanations. In fact doing it this way is better than
what I had in mind. My way would have required executing the program
with each declaration. Thanks.

paolor...@gmail.com

unread,
May 1, 2009, 3:35:57 AM5/1/09
to
On May 1, 5:09 pm, Richard Heathfield <r...@see.sig.invalid> wrote:
> Ike Naar said:
>
> > In article
>
> <4d7228c7-549b-4d0e-a007-ae746034c...@z23g2000prd.googlegroups.com>,

Richard: as Ike has explained I need to get the program running BEFORE
entering declarations and once running I can enter multiple
declarations which is a better model than the one I had in mind.

Richard Heathfield

unread,
May 1, 2009, 5:45:09 AM5/1/09
to
paolor...@gmail.com said:

> On May 1, 5:09 pm, Richard Heathfield <r...@see.sig.invalid>
> wrote:
>> Ike Naar said:
>>

<snip>


>>
>> > That program reads from standard input.
>> > Just type ``dcl'' without arguments at the command line, and
>> > then, while the program is running, type the declarations you
>> > want to have explained, one per line.
>>
>> I think he's asking about how to modify it so that it /does/ take
>> arguments at the command line - argc, argv and all that. I took a
>> quick look - the high level stuff is simple enough, but I don't
>> have the time right now to write a string-chomping version of
>> gettoken().
>>

> Richard: as Ike has explained I need to get the program running
> BEFORE entering declarations and once running I can enter multiple
> declarations which is a better model than the one I had in mind.

See? I can be wrong too. Why, I remember a time back in 1974...

Barry Schwarz

unread,
May 1, 2009, 11:31:45 PM5/1/09
to
On Thu, 30 Apr 2009 20:35:49 -0700 (PDT), paolor...@gmail.com
wrote:

>As a new C learner, I'm coming up against the 'complicated
>declarations' problem i.e. identifying what certain declarations mean.
>So, reading K&R 2nd edition, I came across Section 5.12 Complicated
>Declarations, and thought that the dcl program and its associated
>functions were just what I needed i.e. type 'dcl <declarator>' and a
>word description would pop out. So I have typed in and compiled all
>the code shown (dcl, dirdcl, gettoken etc. as shown on pp. 122-126)
>and called the file dcl.c
>
>Of course, I can't just type 'dcl <declarator>' as the code as shown
>doesn't allow for parsing an argument - none of the functions takes
>any parameters and my C isn't yet up to modifying the code to allow
>that.

The reason the functions don't accept arguments or return values is
that they all use global variables defined at the bottom of page 124
for communication. There is no reason to change the program for that.

There are no prompts for input but if you invoke the program and then
type in a declaration you should get a response.

>
>Would any of the C gurus out there be able illustrate how this might
>be done because I think this program is potentially a great learning
>tool?
>
>TIA

--
Remove del for email

0 new messages