473,320 Members | 1,828 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,320 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 2942
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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
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
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.