473,385 Members | 1,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Rules for complex declarations

I have always had trouble correctly interpreting complex type
declarations without using the "declarator parser" program given in
K&R. Then someone taught me about the "Clockwise" Rule. Start with the
declared item's name and "spiral outwards" in a clockwise direction.
With this rule I was able to guess the type correctly about half the
time (which was still a great improvement).

I recently came across an old (June 1987) article in the C User's Group
Newsletter by Andrew Binstock. I learned that I was not applying the
"Clockwise" Rule correctly. So here it goes:
Take any declaration, start with the innermost parantheses (in the
absence of parantheses start with the declared item's name) and work
clockwise through the declaration GOING TO THE RIGHT FIRST.

It's the GOING TO THE RIGHT FIRST part that I was not applying
correctly (even though I was sprialing outwards in the clockwise
direction), hence the problem. Here are some examples from the
article:

char c; a char
char c[]; an array of char
char *c[]; an array of pointers to chars
char *c(); a function returning a pointer to chars
char* c()[]; a function returning a pointer to an array of chars
int *c()(); a function returning a pointer to a function
returning an int
int (*(*c)[])(); a pointer to an array of pointers to functions
returning an int

In a nutshell:
[] => array of
* => pointer to
(...) => function that returns a/an

Masood

Nov 14 '05 #1
5 2947
ma**********@lycos.com wrote:

I have always had trouble correctly interpreting complex type
declarations without using the "declarator parser" program given in
K&R.


I see that you have posted this message at least five times
in the past 40 minutes. That's four times too many.

--
pete
Nov 14 '05 #2
ma**********@lycos.com wrote:

I have always had trouble correctly interpreting complex type
declarations without using the "declarator parser" program given in
K&R. Then someone taught me about the "Clockwise" Rule. Start with the
declared item's name and "spiral outwards" in a clockwise direction.
With this rule I was able to guess the type correctly about half the
time (which was still a great improvement).


This one is cleaner, but is still posted 5 times in just over one
hour. What can be the purpose of that. It is extremely annoying.

--
"If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
Nov 14 '05 #3
CBFalconer wrote:
ma**********@lycos.com wrote:
I have always had trouble correctly interpreting complex type
declarations without using the "declarator parser" program given in
K&R. Then someone taught me about the "Clockwise" Rule. Start with the
declared item's name and "spiral outwards" in a clockwise direction.
With this rule I was able to guess the type correctly about half the
time (which was still a great improvement).

This one is cleaner, but is still posted 5 times in just over one
hour. What can be the purpose of that. It is extremely annoying.


<ot>

Sometimes after posting, my posts don't appear for a while.
It happened to me once. The poster ends up thinking his
article wasn't posted and posts again. I think this is what has
happened.

(Incidentally, changing the NG server helped).

</ot>

Regards,
Jonathan.

--
"Women should come with documentation." - Dave
Nov 14 '05 #4
On Sun, 23 Jan 2005 18:41:16 +0530, in comp.lang.c , Jonathan Burd
<jo***********@REMOVEMEgmail.com> wrote:
CBFalconer wrote:
This one is cleaner, but is still posted 5 times in just over one
hour. What can be the purpose of that. It is extremely annoying.

Sometimes after posting, my posts don't appear for a while.
It happened to me once. The poster ends up thinking his
article wasn't posted and posts again. I think this is what has
happened.


And sometimes usenet servers return a weird error which looks like a fail
but isn't (I get this occasionally).
--
Mark McIntyre
CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt>

----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
----= East and West-Coast Server Farms - Total Privacy via Encryption =----
Nov 14 '05 #5
On 23 Jan 2005 02:00:35 -0800, ma**********@lycos.com wrote:
I have always had trouble correctly interpreting complex type
declarations without using the "declarator parser" program given in
K&R. Then someone taught me about the "Clockwise" Rule. Start with the
declared item's name and "spiral outwards" in a clockwise direction.
With this rule I was able to guess the type correctly about half the
time (which was still a great improvement).

I recently came across an old (June 1987) article in the C User's Group
Newsletter by Andrew Binstock. I learned that I was not applying the
"Clockwise" Rule correctly. So here it goes:
Take any declaration, start with the innermost parantheses (in the
absence of parantheses start with the declared item's name) and work
clockwise through the declaration GOING TO THE RIGHT FIRST.

It's the GOING TO THE RIGHT FIRST part that I was not applying
correctly (even though I was sprialing outwards in the clockwise
direction), hence the problem. Here are some examples from the
article:

char c; a char
char c[]; an array of char
char *c[]; an array of pointers to chars
char *c(); a function returning a pointer to chars
char* c()[]; a function returning a pointer to an array of chars
int *c()(); a function returning a pointer to a function
returning an int
This one looks like a syntax error. For the description you provide,
you need
int (*c())();
int (*(*c)[])(); a pointer to an array of pointers to functions
returning an int

In a nutshell:
[] => array of
* => pointer to
(...) => function that returns a/an

Masood


<<Remove the del for email>>
Nov 14 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mike | last post by:
Note: My XML experience to date has (unfortunately) been limited to reading and thinking, rather than implementation. Anyway, I am in the process of trying to figure out the most efficient way...
4
by: John Ratliff | last post by:
I have a few global variables in my app. They are defined in the main application class file and declared (extern) in a header which can be included by anyone who would want to use these variables....
4
by: Carl-Olof Almbladh | last post by:
Dear all, In C99, complex is now built in, and the C library contains functions for complex exp, etc. It is not so easy to find info about the syntax if one is not willing to buy the ISO/ANSI...
0
by: masood.iqbal | last post by:
I have always had trouble correctly interpreting complex type declarations without using the "declarator parser" program given in K&R. Then someone taught me about the "Clockwise" Rule. Start with...
3
by: fctk | last post by:
are the following rules correct in C89/C90? ---- SCOPE RULES 1) the scope of an identifier declared inside a block is the block in which it is declared; 2) when you have nested blocks...
13
by: fctk | last post by:
source: http://rm-f.net/~orange/devel/specifications/c89-draft.html#3.1.2.2 there are two passages in this paragraph i can't fully understand: 1) "If the declaration of an identifier for an...
14
by: David Marsh | last post by:
Can someone show me or point me to an example of declaring and initializing complex numbers in C99? Also, in looking at complex.h, I don't see any library calls for + - * or /. How are the basic...
11
by: Grizlyk | last post by:
New C++ rules are always trying to do "fast" compilation - to compile code, which must be compiled at point of instance only (not during declaration stage). The behaviour is intoducing many wrong...
11
by: nospam | last post by:
Is there a utility that takes an arbitrarily complex C language declaration, checks it validity, and breaks it down into something more understandable. Is there a executable version for wintel...
9
by: void main | last post by:
I'm rather new to complex numbers in C and was wondering, how do I initialize a complex variable properly if the imaginary part is 0. I tried -------- #include <complex.h> float complex c...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.