Article may be outdated

This article is 62 days old. Some details may have changed since publication.

Hacker News·5 min read·hard

The C ``Clockwise/Spiral Rule''

E
etrvic
✦AI Summary

The 'Clockwise/Spiral Rule' is a mnemonic technique developed by David Anderson in 1994 to help C programmers parse complex variable declarations. The method involves spiraling through tokens in a declaration to translate them into plain English.

Why it matters

It remains a classic educational tool for understanding the often-confusing syntax of the C programming language.

✦Dive DeeperCreate a free account to unlock

[This was posted to comp.lang.c by its author, David Anderson, on 1994-05-06.]

There is a technique known as the ``Clockwise/Spiral Rule'' which enables any C programmer to parse in their head any C declaration!

Starting with the unknown element, move in a spiral/clockwise direction; when ecountering the following elements replace them with the corresponding english statements:

=> Array X size of... or Array undefined size of...

=> function passing type1 and type2 returning...

Keep doing this in a spiral/clockwise direction until all tokens have been covered.

Always resolve anything in parenthesis first!

We move in a spiral clockwise direction starting with `str' and the first character we see is a `[' so, that means we have an array, so...

Continue in a spiral clockwise direction, and the next thing we encounter is the `*' so, that means we have pointers, so...

Continue reading on Headlinne

Create a free account to read the full article.

Read full article →
technologyeducation
✦

Get smarter about the news

Sign up free for a feed built around what you actually care about, Dive Deeper research on any story, and the full text of every article.

Create free account

Already have an account? Sign in