Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Aug 3rd, 2011, 8:15 AM   #1
Adak
Hobby Coder
 
Join Date: May 2006
Posts: 1,181
Rep Power: 9 Adak will become famous soon enough
Going around in Circles!

C style declarations, quickly get difficult to figure out. This website, shows the "clockwise spiral rule" to help ease that problem.

http://c-faq.com/decl/spiral.anderson.html

This is just one example, showing the problem:

Example #2: Pointer to Function declaration

                     +--------------------+
                     | +---+              |
                     | |+-+|              |
                     | |^ ||              |
                char *(*fp)( int, float *);
                 ^   ^ ^  ||              |
                 |   | +--+|              |
                 |   +-----+              |
                 +------------------------+

Question we ask ourselves: What is fp?

    ``fp is a... 

    * Moving in a spiral clockwise direction, the first thing we see is a `)'; therefore, fp is inside parenthesis, so we continue the spiral inside the parenthesis and the next character seen is the `*', so...

          ``fp is a pointer to... 

    * We are now out of the parenthesis and continuing in a spiral clockwise direction, we see the `('; therefore, we have a function, so...

          ``fp is a pointer to a function passing an int and a pointer to float returning... 

    * Continuing in a spiral fashion, we then see the `*' character, so...

          ``fp is a pointer to a function passing an int and a pointer to float returning a pointer to... 

    * Continuing in a spiral fashion we see the `;', but we haven't visited all tokens, so we continue and finally get to the type `char', so...

          ``fp is a pointer to a function passing an int and a pointer to float returning a pointer to a char''


I am SO glad that the Go language I'm studying atm, has their declarations read ONLY from left to right! This clockwise spiral methodology quickly becomes bizarre once you move beyond simple declarations.
Adak is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Data base saving smats C# 3 Mar 1st, 2010 11:52 AM
Drawing a circle Nuxly Stardust Software Design and Algorithms 7 Jul 25th, 2009 11:34 AM
SMAC #7 [05-09] - Wireless (Advanced) Sane Software Design and Algorithms 2 Jun 4th, 2009 8:47 PM
Microsoft, visual studio and circles bja888 Other Programming Languages 7 Oct 21st, 2005 4:28 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:12 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC