Cyclone (programming language)

1

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: To maintain the tool set that C programmers are used to, Cyclone provides the following extensions: 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 types

Cyclone implements three kinds of pointer: The purpose of introducing these new pointer types is to avoid common problems when using pointers. Take for instance a function, called that takes a pointer to an int: Although the person who wrote the function could have inserted checks, let us assume that for performance reasons they did not. Calling 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. Thus, the "safe" version of would be: This tells the Cyclone compiler that the argument to should never be , avoiding the aforementioned undefined behavior. The simple change of to saves the programmer from having to write checks and the operating system from having to trap 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) function, written in C: This function assumes that the string being passed in is terminated by. However, what would happen if char buf[6] = {'h','e','l','l','o','!'}; were passed to this string? This is perfectly legal in C, yet would cause to iterate through memory not necessarily associated with the string. There are functions, such as which can be used to avoid such problems, but these functions are not standard with every implementation of ANSI C. The Cyclone version of is not so different from the C version: Here, 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 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 allocates an array of chars on the stack and returns a pointer to the start of. However, the memory used on the stack for 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. 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, the Cyclone compiler would see that is a pointer into the local stack, and would report an error.

This article is derived from Wikipedia and licensed under CC BY-SA 4.0. View the original article.

Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc.
Bliptext is not affiliated with or endorsed by Wikipedia or the Wikimedia Foundation.

Edit article