ArticleslgStudy

science

Cyclone (programming language)

Cyclone (programming language) is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Cyclone (programming language) rather than just read about it. In short: The Cyclone programming language was intended to be a safe dialect of the C language. It avoids buffer overflows and other vulnerabilities that are possible in C programs by design, without losing the power and convenience of C as a tool for system programming.

Key takeaways

  • Cyclone (programming language) belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Cyclone (programming language) to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Cyclone (programming language) from memory before moving on to harder problems.

Reference excerpt

The Cyclone programming language was intended to be a safe dialect of the C language. It avoids buffer overflows and other vulnerabilities that are possible in C programs by design, without losing the power and convenience of C as a tool for system programming. It is no longer supported by its original developers, with the reference tooling not supporting 64-bit platforms. The Rust language is mentioned by the original developers for having integrated many of the same ideas Cyclone had. Cyclone development was started as a joint project of Trevor Jim from AT&T Labs Research and Greg Morrisett's group at Cornell University in 2001. Version 1.0 was released on May 8, 2006.

Language features Cyclone attempts to avoid some of the common pitfalls of C, while still maintaining its look and performance. To this end, Cyclone places the following limits on programs:

NULL checks are inserted to prevent segmentation faults Pointer arithmetic is limited Pointers must be initialized before use (this is enforced by definite assignment analysis) Dangling pointers are prevented through region analysis and limits on free() Only "safe" casts and unions are allowed goto into scopes is disallowed switch labels in different scopes are disallowed Pointer-returning functions must execute return setjmp and longjmp are not supported To maintain the tool set that C programmers are used to, Cyclone provides the following extensions:

Never-NULL pointers do not require NULL checks "Fat" pointers support pointer arithmetic with run-time bounds checking Growable regions support a form of safe manual memory management Garbage collection for heap-allocated values Smart pointers, such as unique pointers Region-based memory management Tagged unions support type-varying arguments Injections help automate the use of tagged unions for programmers Polymorphism replaces some uses of void* Variadic arguments are implemented as fat pointers Exceptions replace some uses of setjmp and longjmp Namespaces Type inference Pattern matching Templates, parameterized types Cyclone looks, in general, much like C, but it should be viewed as a C-like language.

Pointer types Cyclone implements three kinds of pointer:

* (the normal type) @ (the never-NULL pointer), and ? (the only type with pointer arithmetic allowed, "fat" pointers). The purpose of introducing these new pointer types is to avoid common problems when using pointers. Take for instance a function, called foo that takes a pointer to an int:

Although the person who wrote the function foo could have inserted NULL checks, let us assume that for performance reasons they did not. Calling foo(NULL); will result in undefined behavior (typically, although not necessarily, a SIGSEGV signal being sent to the application). To avoid such problems, Cyclone introduces the @ pointer type, which can never be NULL. Thus, the "safe" version of foo would be:

This tells the Cyclone compiler that the argument to foo should never be NULL, avoiding the aforementioned undefined behavior. The simple change of * to @ saves the programmer from having to write NULL checks and the operating system from having to trap NULL pointer dereferences. This extra limit, however, can be a rather large stumbling block for most C programmers, who are used to being able to manipulate their pointers directly with arithmetic. Although this is desirable, it can lead to buffer overflows and other "off-by-one"-style mistakes. To avoid this, the ? pointer type is delimited by a known bound, the size of the array. Although this adds overhead due to the extra information stored about the pointer, it improves safety and security. Take for instance a simple (and naïve) strlen function, written in C:

This function assumes that the string being passed in is terminated by '\0'. If this code was passed the unterminated string char buf[6] = {'h','e','l','l','o','!'};, strlen would iterate beyond the end of the string, into memory not associated with the string. Non ANSI C functions such as strnlen seek to address such problems. The Cyclone's strlen is similar to the C version:

Here, strlen bounds itself by the length of the array passed to it. Each of the kinds of pointer type can be safely cast to each of the others, and arrays and strings are automatically cast to ? by the compiler. (Casting from ? to * invokes a bounds check, and casting from ? to @ invokes both a NULL check and a bounds check. Casting from * to ? results in no checks whatsoever; the resulting ? pointer has a size of 1.)

Dangling pointers and region analysis Consider the following code, in C:

The function itoa allocates an array of chars buf on the stack and returns a pointer to the start of buf. However, the memory used on the stack for buf is deallocated when the function returns, so the returned value cannot be used safely outside of the function. While GNU Compiler Collection and other compilers will warn about such code, the following will typically compile without warnings:

GNU Compiler Collection can produce warnings for such code as a side-effect of option -O2 or -O3, but there are no guarantees that all such errors will be detected. Cyclone does regional analysis of each segment of code, preventing dangling pointers, such as the one returned from this version of itoa. All of the local variables in a given scope are considered to be part of the same region, separate from the heap or any other local region. Thus, when analyzing itoa, the Cyclone compiler would see that z is a pointer into the local stack, and would report an error.

Fat pointers A fat pointer is used for allowing pointer arithmetic. Fat pointers must be declared with @fat. For example, argv is often declared as type char** (a pointer to a pointer to a character), or alternatively thought of as char*[] (pointer to an array of characters). In Cyclone, this is instead expressed as char*@fat*@fat (a fat pointer to a fat pointer to characters). Cyclone instead allows ? to represent *@fat. Thus, the two declarations are equivalent:

Parameterized types Similar to templates in C++, Cyclone has a form of generic programming.

An "abstract" type can be used, that encapsulates the implementation type but ensures the definition does not leak to the client.

Namespaces Namespaces exist in Cyclone, similar to C++. Namespaces are used to avoid name clashes in code, and follow the :: notation as in C++. Namespaces can be nested.

Pattern matching Pattern-matching can be accomplished in Cyclone like so:

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Cyclone (programming language)

Start with the simplest possible case. Write down what Cyclone (programming language) claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Cyclone (programming language) before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Cyclone (programming language) ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Cyclone (programming language)

In research
Cyclone (programming language) appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Cyclone (programming language) in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Cyclone (programming language) is common in secondary-school and first-year university syllabi. It links to neighbouring topics C programming language family, Programming languages created in 2002, so understanding it makes those chapters shorter.
In everyday life
Look for Cyclone (programming language) outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Cyclone (programming language)” →

How to study Cyclone (programming language) in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Cyclone (programming language) means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Cyclone (programming language) out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Cyclone (programming language) in simple terms?

The Cyclone programming language was intended to be a safe dialect of the C language. It avoids buffer overflows and other vulnerabilities that are possible in C programs by design, without losing the power and convenience of C as a tool for system programming.

Why does Cyclone (programming language) matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Cyclone (programming language)?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Cyclone (programming language).

Tags

  • C programming language family
  • Programming languages created in 2002

Keep exploring