Microsoft C Compiler: Inline variable declaration?
Posted
by Rosarch
on Stack Overflow
See other posts from Stack Overflow
or by Rosarch
Published on 2010-01-31T02:42:40Z
Indexed on
2010/04/06
2:03 UTC
Read the original article
Hit count: 383
I'm writing C in Visual Studio 2010. The compiler doesn't seem to want to let me use inline variable declarations. The following code produces an error:
unsigned int fibonacci_iterative(unsigned int n) {
if (n == 0) {
return 0;
}
if (n == 1) {
return 1;
}
unsigned int prev_prev = 0; // error
unsigned int prev = 1; // error
unsigned int next = 0; // error
for (int term_number = 0; term_number < n; term_number++) {
unsigned int temp = prev_prev + prev;
prev = next;
prev_prev = prev;
next = temp;
}
return next;
}
Error:
error C2143: syntax error : missing ';' before 'type'
error C2143: syntax error : missing ';' before 'type'
error C2143: syntax error : missing ';' before 'type'
Why is this happening? Is there a setting to make the compiler not so strict?
© Stack Overflow or respective owner