World Library  
Flag as Inappropriate
Email this Article

Cyclone (programming language)

Article Id: WHEBN0000007645
Reproduction Date:

Title: Cyclone (programming language)  
Author: World Heritage Encyclopedia
Language: English
Subject: Generational list of programming languages, Hermes (programming language), Definite assignment analysis, ML (programming language), Region-based memory management
Collection: C Programming Language Family
Publisher: World Heritage Encyclopedia

Cyclone (programming language)

Designed by AT&T Labs
Appeared in 2006 (2006)
Stable release 1.0 / May 8, 2006 (2006-05-08)
Influenced by C
Website .org.thelanguagecyclone

The Cyclone programming language is intended to be a safe dialect of the C language. Cyclone is designed to avoid buffer overflows and other vulnerabilities that are endemic in C programs, without losing the power and convenience of C as a tool for system programming.

Cyclone development was started as a joint project of AT&T Labs Research and Greg Morrisett's group at Cornell in 2001. Version 1.0 was released on May 8, 2006.


  • Language features 1
    • Pointer/reference types 1.1
    • Dangling pointers and region analysis 1.2
    • Manual memory management 1.3
  • Examples 2
  • See also 3
  • References 4
  • External links 5

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:

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
  • Tagged unions support type-varying arguments
  • Injections help automate the use of tagged unions for programmers
  • Polymorphism replaces some uses of void *
  • varargs are implemented as fat pointers
  • Exceptions replace some uses of setjmp and longjmp

For a better high-level introduction to Cyclone, the reasoning behind Cyclone and the source of these lists, see this paper.

Cyclone looks, in general, much like C, but it should be viewed as a C-like language.

Pointer/reference types

Cyclone implements three kinds of reference (following C terminology these are called pointers):

  • * (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:

 int foo(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 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:

 int foo(int @);

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:

 int strlen(const char *s)
     int iter = 0;
     if (s == NULL)
        return 0;
     while (s[iter] != '\0') {
     return iter;

This function assumes that the string being passed in is terminated by NULL ('\0'). However, what would happen if char buf[] = {'h','e','l','l','o','!'}; were passed to this string? This is perfectly legal in C, yet would cause strlen to iterate through memory not necessarily associated with the string s. There are functions, such as strnlen which can be used to avoid such problems, but these functions are not standard with every implementation of ANSI C. The Cyclone version of strlen is not so different from the C version:

 int strlen(const char ? s)
    int iter, n = s.size;
    if (s == NULL)
       return 0;
    for (iter = 0; iter < n; iter++, s++) {
       if (*s == '\0')
          return iter;
    return n;

Here, strlen bounds itself by the length of the array passed to it, thus not going over the actual length. 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 * or ? results in no checks whatsoever; the resulting ? pointer has a size of 1.)

Dangling pointers and region analysis

Consider the following code, in C:

 char *itoa(int i)
    char buf[20];
    return buf;

This returns an object that is allocated on the stack of the function itoa, which is not available after the function returns. While gcc and other compilers will warn about such code, the following will typically compile without warnings:

 char *itoa(int i)
    char buf[20], *z;
    z = buf;
    return z;

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 compiler would see that z is a pointer into the local stack, and would report an error.

Manual memory management


The best example to start with is the classic Hello world program:

 using Core;
 int main(int argc, string_t ? args)
    if (argc <= 1) {
       printf("Usage: hello-cyclone \n");
       return 1;
    printf("Hello from Cyclone, %s\n", args[1]);
    return 0;

See also


  • Cyclone User Manual
  • Cyclone: a Type-safe Dialect of C by Dan Grossman, Michael Hicks, Trevor Jim, and Greg Morrisett - published January 2005

External links

  • Cyclone Homepage
  • Old web site since official web site is not available.
  • Cyclone 1.0 source code RPM
  • Cyclone - Source code repositories
  • Cyclone - FAQ
  • Cyclone for C programmers


  • Cyclone: A Type-Safe Dialect of C
  • Cyclone: A Memory-Safe C-Level Programming Language
This article was sourced from Creative Commons Attribution-ShareAlike License; additional terms may apply. World Heritage Encyclopedia content is assembled from numerous content providers, Open Access Publishing, and in compliance with The Fair Access to Science and Technology Research Act (FASTR), Wikimedia Foundation, Inc., Public Library of Science, The Encyclopedia of Life, Open Book Publishers (OBP), PubMed, U.S. National Library of Medicine, National Center for Biotechnology Information, U.S. National Library of Medicine, National Institutes of Health (NIH), U.S. Department of Health & Human Services, and, which sources content from all federal, state, local, tribal, and territorial government publication portals (.gov, .mil, .edu). Funding for and content contributors is made possible from the U.S. Congress, E-Government Act of 2002.
Crowd sourced content that is contributed to World Heritage Encyclopedia is peer reviewed and edited by our editorial staff to ensure quality scholarly research articles.
By using this site, you agree to the Terms of Use and Privacy Policy. World Heritage Encyclopedia™ is a registered trademark of the World Public Library Association, a non-profit organization.

Copyright © World Library Foundation. All rights reserved. eBooks from Project Gutenberg are sponsored by the World Library Foundation,
a 501c(4) Member's Support Non-Profit Organization, and is NOT affiliated with any governmental agency or department.