c - MSVC syntax error with if statement and variable declaration -


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

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -