Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual c++ "for each" portability

Tags:

I only just recently discovered that Visual C++ 2008 (and perhaps earlier versions as well?) supports for each syntax on stl lists et al to facilitate iteration. For example:

list<Object> myList;  for each (Object o in myList) {   o.foo(); } 

I was very happy to discover it, but I'm concerned about portability for the dreaded day when someone decides I need to be able to compile my code in say, gcc or some other compiler. Is this syntax widely supported and can I use it without worrying about portability issues?

like image 836
korona Avatar asked Oct 13 '08 12:10

korona


People also ask

What is the difference between Visual C and C?

Key Differences Between C++ and Visual C++C++ is an object-oriented programming language, whereas Visual C++ is the Integrated Development Environment (IDE) and compiler for C and C++ language. In C++, a compiler translates the C++ program code into machine code which computers can understand and execute the same.

What C standard does Visual Studio use?

The /std:c17 option enables ISO C17 conformance. It's available starting in Visual Studio 2019 version 16.8.

Does visual studios support C?

Yes, you very well can learn C using Visual Studio. Visual Studio comes with its own C compiler, which is actually the C++ compiler. Just use the . c file extension to save your source code.

Is Visual Studio only for C?

Visual Studio Code is a lightweight, cross-platform development environment that runs on Windows, Mac, and Linux systems. The Microsoft C/C++ for Visual Studio Code extension supports IntelliSense, debugging, code formatting, auto-completion. Visual Studio for Mac doesn't support Microsoft C++, but does support .


1 Answers

I wouldn't use that. While it's a tempting feature, the syntax is incompatible with the upcoming C++0x standard, which uses:

list<Object> myList;  for (Object o : myList) {    o.foo(); } 

to do the same thing.

like image 181
Ferruccio Avatar answered Sep 30 '22 18:09

Ferruccio