Cyclone (programming language): Difference between revisions

Content deleted Content added
m Task 70: Update syntaxhighlight tags - remove use of deprecated <source> tags
Bender the Bot (talk | contribs)
m top: HTTP to HTTPS for Cornell University
 
(26 intermediate revisions by 17 users not shown)
Line 1:
{{noShort footnotesdescription|date=AugustMemory-safe 2015}}{{Infoboxdialect of the C programming language}}
{{use dmy dates|date=August 2024}}
{{more footnotes|date=August 2015}}
{{Infobox programming language
| name = Cyclone
| logo =
| logo caption =
| file ext =
| paradigm =
| released = {{startStart date and age|2002}}
| designer = [[AT&T Labs]]
| developer = [[Cornell University]]
| latest release version = 1.0
| latest release date = {{startStart date and age|2006|05|08}}
| latest preview version =
| latest preview date = <!-- {{start date and age|YYYY|MM|DD}} -->
Line 16 ⟶ 19:
| dialects =
| influenced by = [[C (programming language)|C]]
| influenced = [[Rust (programming language)|Rust]], [[Project Verona]]
| programming language =
| operating system =
Line 22 ⟶ 25:
| website = {{URL|http://cyclone.thelanguage.org}}
| wikibooks =
| discontinued = Yes<ref>{{cite web |title=Open Access Cyclone (programming language) Journals · OA.mg |url=https://oa.mg/journals/open-access-cyclone-programming-language-journals |website=oa.mg |access-date=30 October 2022 |archive-date=30 October 2022 |archive-url=https://web.archive.org/web/20221030192542/https://oa.mg/journals/open-access-cyclone-programming-language-journals |url-status=live }}</ref>
| discontinued = yes
}}
The '''Cyclone''' [[programming language]] iswas intended to be a safe dialect of the [[C (programming language)|C language]].<ref>{{Cite journal |last1=Jim |first1=Trevor |last2=Morrisett |first2=J. Greg |last3=Grossman |first3=Dan |last4=Hicks |first4=Michael W. |last5=Cheney |first5=James |last6=Wang |first6=Yanling |date=2002-06-10 |title=Cyclone: isA designedSafe toDialect of C |url=https://dl.acm.org/doi/10.5555/647057.713871 |journal=Proceedings of the General Track of the Annual Conference on USENIX Annual Technical Conference |series=ATEC '02 |___location=USA |publisher=USENIX Association |pages=275–288 |isbn=978-1-880446-00-3}}</ref> It avoidavoids [[buffer overflow]]s 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 computing|64-bit platforms]]. The [[Rust (programming language)|Rust]] language is mentioned by the original developers for having integrated many of the same ideas Cyclone had.<ref>{{cite web |title=Cyclone |url=http://cyclone.thelanguage.org/ |website=cyclone.thelanguage.org |access-date=11 December 2023 |archive-date=21 May 2006 |archive-url=https://web.archive.org/web/20060521202022/http://cyclone.thelanguage.org/ |url-status=live }}</ref>
 
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.<ref>{{cite web |title=Cyclone |url=https://www.cs.cornell.edu/Projects/cyclone/ |website=[[Cornell University]] |access-date=30 October 2022 |archive-date=15 October 2022 |archive-url=https://web.archive.org/web/20221015034248/https://www.cs.cornell.edu/Projects/cyclone/ |url-status=live }}</ref>
 
==Language features==
Line 33 ⟶ 36:
* [[Pointer arithmetic]] is limited
* Pointers must be initialized before use (this is enforced by [[definite assignment analysis]])
* [[Dangling pointer]]s are prevented through region analysis and limits on [[Malloc|<code>[[free()]]</code>]]
* Only "safe" casts and unions are allowed
* [[Control flow|<code>goto</code>]] into scopes is disallowed
* [[Control flow|<code>switch</code>]] labels in different scopes are disallowed
* Pointer-returning functions must execute <code>return</code>
* [[Setjmp/longjmp.h|<code>setjmp</code>]] and [[Setjmp/longjmp|<code>longjmp</code>]] are not supported
 
To maintain the tool set that C programmers are used to, Cyclone provides the following extensions:
Line 53 ⟶ 56:
For a better high-level introduction to Cyclone, the reasoning behind Cyclone and the source of these lists, see [http://www.cs.umd.edu/projects/cyclone/papers/cyclone-safety.pdf this paper].
 
Cyclone looks, in general, much like [[C (programming language)|C]], but it should be viewed as a C-like language.
 
===Pointer types===
Line 72 ⟶ 75:
int strlen(const char *s)
{
int iteri = 0;
if (s == NULL)
return 0;
while (s[iteri] != '\0') {
iteri++;
}
return iteri;
}
</syntaxhighlight>
This function assumes that the string being passed in is terminated by NULL (<code>'\0'</code>). However, what would happen if <{{code>|style=white-space:nowrap|2=c|1=char&nbsp; buf[6]&nbsp; =&nbsp; {'h','e','l','l','o','!'};</code>}} were passed to this string? This is perfectly legal in C, yet would cause <code>strlen</code> to iterate through memory not necessarily associated with the string <code>s</code>. There are functions, such as <code>strnlen</code> which can be used to avoid such problems, but these functions are not standard with every implementation of [[ANSI C]]. The Cyclone version of <code>strlen</code> is not so different from the C version:
<syntaxhighlight lang="C">
int strlen(const char ? s)
{
int iteri, n = s.size;
if (s == NULL)
return 0;
for (iteri = 0; iteri < n; iteri++, s++) {
if (*s == '\0')
return iteri;
}
return n;
}
Line 107 ⟶ 109:
}
</syntaxhighlight>
FunctionThe function <code>itoa</code> allocates an array of chars <code>buf</code> on the stack and returns a pointer to the start of <code>buf</code>. However, the memory used on the stack for <code>buf</code> is deallocated when the function returns, so the returned value cannot be used safely outside of the function. While [[GNU Compiler Collection|gcc]] and other compilers will warn about such code, the following will typically compile without warnings:
<syntaxhighlight lang="C">
char *itoa(int i)
Line 117 ⟶ 119:
}
</syntaxhighlight>
[[GNU Compiler Collection|gcc]] can produce warnings for such code as a side-effect of option {{code|-O2}} or {{code|-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 <code>itoa</code>. 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 <code>itoa</code>, the Cyclone compiler would see that <code>z</code> is a pointer into the local stack, and would report an error.
 
Line 126 ⟶ 128:
 
==References==
{{Reflist}}
 
* [http://cyclone.thelanguage.org/wiki/User%20Manual Cyclone User Manual]
* [http://www.cs.umd.edu/~mwh/papers/cyclone-cuj.pdf Cyclone: a Type-safe Dialect of C] by Dan Grossman, Michael Hicks, Trevor Jim, and Greg Morrisett - published January 2005
 
==External links==
* [http://cyclone.thelanguage.org/ Cyclone Homepagehomepage]
* [https://web.archive.org/web/20111227232825/http://www.eecs.harvard.edu/~greg/cyclone/old_cyclone.html Old web site] since official web site is not available.
* [http://cyclone.thelanguage.org/wiki/Download Cyclone - Sourcesource code repositories]
* [http://cyclone.thelanguage.org/wiki/Frequently%20Asked%20Questions Cyclone - FAQ]
* [http://cyclone.thelanguage.org/wiki/Cyclone%20for%20C%20Programmers Cyclone for C programmers]
* [http://cyclone.thelanguage.org/wiki/User%20Manual Cyclone Useruser Manualmanual]
* [http://www.cs.umd.edu/~mwh/papers/cyclone-cuj.pdf Cyclone: a Type-safe Dialect of C] by Dan Grossman, Michael Hicks, Trevor Jim, and Greg Morrisett - published January 2005
 
Presentations:
Line 145 ⟶ 147:
{{DEFAULTSORT:Cyclone (Programming Language)}}
[[Category:C programming language family]]
[[Category:Programming languages created in 2002]]