c - MSVC syntax error with if statement and variable declaration -
this question has answer here:
i can't figure 1 out. plain c compiled msvc compiler on command-line.
microsoft (r) 32-bit c/c++ optimizing compiler version 15.00.30729.01 80x86
copyright (c) microsoft corporation. rights reserved.
with if (null == string) { return null; }
block, 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 compiles fine without if-block. can't see what's wrong here.
char* drift_charbuffer_tostring(const drift_charbuffer* buffer) { // todo: utf-8 encoding characters outside ascii-range. char* string = drift_alloc(buffer->count + 1); if (null == string) { return null; } int index; // line: 78 (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; }
well, "plain c" c99 or post-c99 c. meanwhile, msvc compiler supports "classic old plain c" aka c89/90. in classic c illegal mix statements , declarations. declarations have done @ top of block.
Comments
Post a Comment