typdef problem with C source files in VS 2010

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • akevan
    New Member
    • Dec 2010
    • 4

    #1

    typdef problem with C source files in VS 2010

    Hi all,

    I've got a VS 2010 project that makes some pretty standard typedefs like:

    Code:
    typedef int mlInt;
    ... and a function that looks like:
    Code:
    void mlVecMult(int length, int* vec1, int* vec2, int* vecOut);
    In my .c file (vector.c), I have a basic implementation:
    Code:
    void mlVecMult(mlInt length, mlInt* vec1, mlInt* vec2, mlInt* vecOut)
    {
    	for(mlInt i=0; i < length; i++)
    	{
    		vecOut[i] = vec1[i] * vec2[i];
    	}
    }
    So when I compile this, the compiler gives a ton of errors like:

    ml_vector.c(5): error C2143: syntax error : missing ';' before 'type'

    .. so it doesn't find the type properly. BUT if I change the extension of the file vector.c to .cpp, it works fine.

    Is this some C syntax thing I'm forgetting? Thanks for any help.
  • donbock
    Recognized Expert Top Contributor
    • Mar 2008
    • 2427

    #2
    You define variable i within the for statement in function mlVecMult. You couldn't do that in C until C99.
    • Move the definition to a line of its own prior to the for statement.
    • Investigate whether you need to set some command line switch or VS 2010 option to select C99.

    Comment

    • akevan
      New Member
      • Dec 2010
      • 4

      #3
      Of course... that's standard C. Thanks!! Taking a while to remember all these little differences between ANSI C and C++.

      Comment

      Working...