none
problem with for(int i=0;i<n;i++) ??

    Question

  • Hi All,

    I have VS2013 that normally supports the C99 features but I get problem with compiling using C for any code

    that contains  this syntax for(int i=0;i<n;i++).

    so why VS2013 does not support this syntax while it supports C99?

    is there any way to resolve that problem?

    thanks.

    Wednesday, October 30, 2013 1:03 PM

Answers

All replies

  • You should save your source file as CPP, not C file.

    C does not support variable declarations in for loops in the way you did.

    In C your code should be:

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


    Best regards

    Bordon

    Note: Posted code pieces may not have a good programming style and may not perfect. It is also possible that they do not work in all situations. Code pieces are only indended to explain something particualar.



    • Edited by Bordon Wednesday, October 30, 2013 2:16 PM
    • Proposed as answer by Brian MuthMVP Wednesday, October 30, 2013 2:47 PM
    Wednesday, October 30, 2013 2:14 PM
  • I have VS2013 that normally supports the C99 features but I get problem with compiling using C for any code

    that contains  this syntax for(int i=0;i<n;i++).


    What problem do you get when you compile ‘for (int i = 0; i < 10; i++) { }’ in a .c file in Visual Studio 2013 with default configuration?



    • Edited by Viorel_MVP Wednesday, October 30, 2013 2:30 PM
    Wednesday, October 30, 2013 2:28 PM
  • You should save your source file as CPP, not C file.

    C does not support variable declarations in for loops in the way you did.

    In C your code should be:

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


    Best regards

    Bordon

    Note: Posted code pieces may not have a good programming style and may not perfect. It is also possible that they do not work in all situations. Code pieces are only indended to explain something particualar.




    my code should be compiled as C, so this will not resolve the issue.
    Wednesday, October 30, 2013 5:01 PM
  • I have VS2013 that normally supports the C99 features but I get problem with compiling using C for any code

    that contains  this syntax for(int i=0;i<n;i++).


    What problem do you get when you compile ‘for (int i = 0; i < 10; i++) { }’ in a .c file in Visual Studio 2013 with default configuration?




    I get this error: error C2143: syntax error : missing ';' before 'type'.

    Wednesday, October 30, 2013 5:04 PM
  • I have VS2013 that normally supports the C99 features but I get problem with compiling using C for any code

    that contains  this syntax for(int i=0;i<n;i++).

    so why VS2013 does not support this syntax while it supports C99?

    The simple answer is that VC++ 2013 doesn't support *all* of C99 (by design.)

    - Wayne

    Wednesday, October 30, 2013 7:48 PM
  • The longer answer may be found here:

    http://connect.microsoft.com/VisualStudio/feedback/details/800085/c99-compiler-error-when-declaring-variable-in-for-loop

    Are you still using the RC version of VS2013?

    If so, you should try using the RTM version which has now been released - including the
    Express Edition.

    - Wayne


    • Proposed as answer by Pavel A Wednesday, October 30, 2013 10:37 PM
    • Marked as answer by Yuri.B Thursday, October 31, 2013 7:42 AM
    Wednesday, October 30, 2013 8:13 PM
  • The longer answer may be found here:

    http://connect.microsoft.com/VisualStudio/feedback/details/800085/c99-compiler-error-when-declaring-variable-in-for-loop

    Are you still using the RC version of VS2013?

    If so, you should try using the RTM version which has now been released - including the
    Express Edition.

    - Wayne



    yes I'm still using the RC version, Are you sure that the RTM version supports this C99 feature?
    • Marked as answer by Yuri.B Thursday, October 31, 2013 7:42 AM
    • Unmarked as answer by Yuri.B Thursday, October 31, 2013 7:42 AM
    Wednesday, October 30, 2013 10:42 PM
  • Are you sure that the RTM version supports this C99 feature?

    Did you not understand the reply from Microsoft in the link I gave you?

    - Wayne

    • Marked as answer by Yuri.B Thursday, October 31, 2013 7:41 AM
    • Unmarked as answer by Yuri.B Thursday, October 31, 2013 7:42 AM
    Thursday, October 31, 2013 1:10 AM
  • Hi All,

    I have VS2013 that normally supports the C99 features but I get problem with compiling using C for any code

    that contains  this syntax for(int i=0;i<n;i++).

    so why VS2013 does not support this syntax while it supports C99?

    is there any way to resolve that problem?

    thanks.

    actually that is legal for C++11 as well as C99 but I assume your scope {} are being used when needed

    check for any possible use outside the scope rules etc


    Corsair Carbide 300R with window
    Corsair TX850V2 12V1 70A
    Asus M5A99FX PRO R2.0 CFX/SLI
    AMD Phenom II 965 C3 Black Edition @ 4.0 GHz
    G.SKILL RipjawsX DDR3-2133 8 GB
    EVGA GTX 660 Ti FTW Signature
    Asus PA238QR IPS LED HDMI DP 1080p
    ST2000DM001 & Windows 8.1 x64 Professional
    LG WH14NS40 14X Blu-Ray Writer BDXL 128GB
    Microsoft Wireless Desktop 2000
    Wacom Bamboo CHT470M

    Thursday, October 31, 2013 1:36 AM
  • Are you sure that the RTM version supports this C99 feature?

    Did you not understand the reply from Microsoft in the link I gave you?

    - Wayne

    a ok, I readed the bug described in the link you have given, I understand now.

    I will try the RTM right now.

    thanks!

    Thursday, October 31, 2013 7:41 AM