onmyway133
onmyway133

Reputation: 48085

Visual Studio C function syntax error

I'm trying to implement a C function like this in Visual Studio, I've followed Creating a C Project in Visual Studio

void changeParameters(int &a, int n) {
   for (int i=0; i<n; ++i) {
      printf("some text goes here");
   }
}

However, I receive the following errors

  1. syntax error &
  2. undeclared identifier i

I've tried both VS 2008 and 2010, but the same errors

Is this C99 features? I remember I can compile this kind of code in Visual Studio C++ 6.0

Upvotes: 1

Views: 747

Answers (2)

Vlad from Moscow
Vlad from Moscow

Reputation: 310960

C has no references. This function declaration

void changeParameters(int &a, int n);

defined the first parameter as a reference to int. You can try to change the function declaration as

void changeParameters(int *a, int n);

Take into account that MS VS 2010 does not support even C99 not speaking about the most recent C Standard.

Upvotes: 4

ouah
ouah

Reputation: 145829

for (int i=0; i<n; ++i)

The i declaration in the for loop is a c99 feature, c89 does not support it. It is also supported in C++.

In C also references are not supported (neither in c89 / c99 / c11):

void changeParameters(int &a, int n) 

this function declaration is not valid because of int &a parameter.

Upvotes: 2

Related Questions