I can't figure this one out. Plain C compiled with MSVC Compiler on the command-line.
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.
With the if (NULL == string) { return NULL; }
block, I get a syntax error.
..\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
But it compiles fine without the if-block. I just can't see what's wrong here.
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;
}