开发者

Question about Cyclone

I have read on Wikipedia that the Cyclone programming language is a safe dialect of the C programming language so consider the following C code.

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

This function assumes that the string being passed in is terminated by NUL ('\0'). But if we pass a string like this,

char buf[] = {'h','e','l','l','o','!'}

it would cause strlen to iterate through memory not necessarily associated with the string s. So there is another versio开发者_开发知识库n of this code in Cyclone

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;
}

Can I use Cyclone in Visual Studio or do I have to donwload a new compiler?


You will need Cyclone. It is also the name of the compiler. The Cyclone compiler is available in source code here. The Cyclone compiler can, according to the documentation, only be compiled with GCC. Check this to compile the Cyclone compiler.

You can use it from Visual Studio if you provide custom rules for the *.cyc files. This way you can use the IDE as a better text editor. For syntax highlighting and style assign *.cyc to the C language extention list.


You can run custom tools for a file with a specific filename extension. The MSDN Library article on how to setup the custom build rule is here. Beware that this is pretty broken in VS2010 right now.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜