我在维基百科上读到Cyclone编程语言是C编程语言的安全方言,因此请考虑以下C代码.
int strlen(const char *s)
{
int iter = 0;
if (s == NULL) return 0;
while (s[iter] != '\0') {
iter++;
}
return iter;
}
Run Code Online (Sandbox Code Playgroud)
此函数假定传入的字符串由NUL('\ 0')终止.但是如果我们传递这样的字符串,
char buf[] = {'h','e','l','l','o','!'}
Run Code Online (Sandbox Code Playgroud)
它会导致strlen
迭代通过不一定与字符串s相关联的内存.所以在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;
}
Run Code Online (Sandbox Code Playgroud)
我可以在Visual Studio中使用Cyclone,还是必须下载新的编译器?
你将需要旋风。它也是编译器的名称。Cyclone 编译器的源代码可在此处获取。根据文档,Cyclone编译器只能用GCC编译。检查此项以编译 Cyclone 编译器。
如果您为 *.cyc 文件提供自定义规则,则可以从 Visual Studio 使用它。这样您就可以将 IDE 用作更好的文本编辑器。对于语法突出显示和样式,将 *.cyc 分配给 C 语言扩展列表。
归档时间: |
|
查看次数: |
333 次 |
最近记录: |