By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,949 Members | 1,063 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,949 IT Pros & Developers. It's quick & easy.

typdef problem with C source files in VS 2010

P: 4
Hi all,

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

Expand|Select|Wrap|Line Numbers
  1. typedef int mlInt;
... and a function that looks like:
Expand|Select|Wrap|Line Numbers
  1. void mlVecMult(int length, int* vec1, int* vec2, int* vecOut);
In my .c file (vector.c), I have a basic implementation:
Expand|Select|Wrap|Line Numbers
  1. void mlVecMult(mlInt length, mlInt* vec1, mlInt* vec2, mlInt* vecOut)
  2. {
  3.     for(mlInt i=0; i < length; i++)
  4.     {
  5.         vecOut[i] = vec1[i] * vec2[i];
  6.     }
  7. }
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.
Dec 17 '10 #1

✓ answered by donbock

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.

Share this Question
Share on Google+
2 Replies


Expert 100+
P: 2,396
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.
Dec 17 '10 #2

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

Post your reply

Sign in to post your reply or Sign up for a free account.