我想不通这个。使用 MSVC 编译器在命令行上编译的纯 C。
Microsoft (R) 32 位 C/C++ 优化编译器版本 15.00.30729.01,适用于 80x86
版权所有 (C) Microsoft Corporation。版权所有。
使用该if (NULL == string) { return NULL; }
块,我得到一个语法错误。
..\src\drift_charbuffer.c(78) : error C2143: syntax error : missing ';' before 'type'
..\src\drift_charbuffer.c(79) : error C2065: 'index' : undeclared identifier
..\src\drift_charbuffer.c(79) : error C2065: 'index' : undeclared identifier
..\src\drift_charbuffer.c(79) : error C2065: 'index' : undeclared identifier
..\src\drift_charbuffer.c(81) : error C2065: 'index' : undeclared identifier
..\src\drift_charbuffer.c(85) : error C2065: 'index' : undeclared identifier
..\src\drift_charbuffer.c(87) : error C2065: 'index' : undeclared identifier
但是没有 if 块它编译得很好。我只是看不出这里有什么问题。
char*
drift_charbuffer_tostring(const drift_charbuffer* buffer)
{
// todo: UTF-8 encoding for characters outside the ASCII-range.
char* string = drift_alloc(buffer->count + 1);
if (NULL == string)
{
return NULL;
}
int index; // Line: 78
for (index = 0; index < buffer->count; ++index)
{
int value = *drift_charbuffer_get(buffer, index);
if (value > 127)
value = '?';
string[index] = value;
}
string[index] = 0;
return string;
}