0

I am learning C and use VS 2019 community edition.

While learning C I do not want to use any C++ features accidentally, like declaring the for variable inside the for. E.g. right now this code compiles:

for (int i = 0; i < 100; ++i)
{
  ...
}

But it is not C, it is C++ and I wish the compiler to tell me that.

Is it possible?

Alan Birtles
  • 32,622
  • 4
  • 31
  • 60
  • 1
    That loop is valid since the C99 standard. And Visual Studio is *almost* C99 compliant these days. – Some programmer dude Aug 13 '19 at 05:51
  • I am reading the 2nd edition of "The C programming language" from 1988, so it is not there. But are you saying that if my file has the .c extension, then VS already enforces C? – Ethan Kharitonov Aug 13 '19 at 05:53
  • 2
    You should definitely read the newer edition of the book. 30 years ago... – 273K Aug 13 '19 at 05:54
  • I looked for it, but it seems the 2nd edition is the last one of the book by K&R. What book are you referring too? – Ethan Kharitonov Aug 13 '19 at 05:56
  • 1
    Sorry, your are right. The second edition is the latest, it was published till 98. Then you should read another book. – 273K Aug 13 '19 at 05:58
  • Here is the good set of books https://stackoverflow.com/questions/562303/the-definitive-c-book-guide-and-list – 273K Aug 13 '19 at 06:00
  • Please, before this becomes a discussion about books to read, that is not appropriate for StackOverflow: Could some VS2019 user answer @Ethan's question how to tell VS2019 the standard version of C to use for checking? – the busybee Aug 13 '19 at 06:01
  • 1
    I remember a comment from one of the Microsoft managers a while back. He said they had no interest in supporting C and were concentrating on C++. So if you want to learn standard C, then you might be better with a different compiler. – john Aug 13 '19 at 06:02
  • @thebusybee AFAIK VS has no such option. – john Aug 13 '19 at 06:03
  • Maybe you're looking for this: https://learn.microsoft.com/de-de/cpp/build/reference/za-ze-disable-language-extensions?view=vs-2019 – grek40 Aug 13 '19 at 06:03
  • Why the C++ tag when asking about C? Also, as a starter, take the [tour] and read [ask]. – Ulrich Eckhardt Aug 13 '19 at 06:15
  • 1
    Possible duplicate of [Is there any option to switch between C99 and C11 C standards in Visual Studio?](https://stackoverflow.com/questions/48981823/is-there-any-option-to-switch-between-c99-and-c11-c-standards-in-visual-studio) – Alan Birtles Aug 13 '19 at 06:39

1 Answers1

2

Yes, Visual Studio enforces C compiler by file extension. If it meets .c, then it switches to using of C compiler. There is no option to say VS C compiler which C standard should be used. VS mostly conforms to C99, and doesn't fully support the latest C11. It is due to the fact that VS compiler is C++ compiler, and C programming language support is in the shadow.

Here is the better answer Is there any option to switch between C99 and C11 C standards in Visual Studio?

273K
  • 29,503
  • 10
  • 41
  • 64