Sign in to follow this  
Followers 0
Enerjak

C11 initializer lists not working in visual studio 2010/2012

9 posts in this topic

Ok, i got a book about C11 and all the new features about it. One of them is initializer lists like:

[code]

vector<string> name { "Sonic", "Eggman'" };

[/code]

but they all give this error:

[code]

1 IntelliSense: expected a ';' c:\users\rosario\documents\visual studio 2010\projects\fix\fix\fix.cpp 9 10 Fix

[/code]

of when dealing with vectors, this:

[code]

1 IntelliSense: initialization with '{...}' is not allowed for object of type "std::vector<std::string, std::allocator<std::string>>" c:\users\rosario\documents\visual studio 2010\projects\fix\fix\fix.cpp 9 25 Fix

[/code]

not sure what to do.
0

Share this post


Link to post
Share on other sites
I'd suggest using a different compiler if you want to use C++11 features, Visual Studio has some C++11 support but it's severely lacking when compared to other compilers like GCC.

Some new features including initializer lists have been added in the [url="http://blogs.msdn.com/b/vcblog/archive/2012/11/02/visual-c-c-11-and-the-future-of-c.aspx"]November CTP[/url] for VS2012, but this is pre-release software and can therefore be quite buggy (no word yet on a stable release). They also don't provide an updated version of the standard library with it either, so you wouldn't be able to use these new features with structures defined by the standard library.
2

Share this post


Link to post
Share on other sites
[quote name='Radikalizm' timestamp='1354942217' post='5008367']
I'd suggest using a different compiler if you want to use C++11 features, Visual Studio has some C++11 support but it's severely lacking when compared to other compilers like GCC.

Some new features including initializer lists have been added in the [url="http://blogs.msdn.com/b/vcblog/archive/2012/11/02/visual-c-c-11-and-the-future-of-c.aspx"]November CTP[/url] for VS2012, but this is pre-release software and can therefore be quite buggy (no word yet on a stable release). They also don't provide an updated version of the standard library with it either, so you wouldn't be able to use these new features with structures defined by the standard library.
[/quote]

man, what a buzz kill that is.......thanks, amd apperantly chronos lib is not available for 2010 either
0

Share this post


Link to post
Share on other sites
Neither the VC10 or VC11 compilers support initializer lists, see http://msdn.microsoft.com/en-us/library/vstudio/hh567368.aspx

Your choice is probably quite straightforward:
- Rework the code not to use C++11 initializer lists, or
- Switch to using another compiler that does support them.GCC has initializer lists since GCC 4.4: http://gcc.gnu.org/projects/cxx0x.html . Clang has support for initializer lists since Clang 3.1 http://clang.llvm.org/cxx_status.html . Intel C++ compiler advertizes partial support for initializer lists in 13.0 (I don't know what that means in practice): http://software.intel.com/en-us/articles/c0x-features-supported-by-intel-c-compiler .
2

Share this post


Link to post
Share on other sites
[quote name='KingofNoobs' timestamp='1354951852' post='5008417']
Can one use the VC11 IDE with the GCC or other compilers?
[/quote]
I know you can use the Intel compiler (google may know more); I haven't heard of anyone using GCC with Visual Studio. Also, I'm not sure if changing compilers impacts any Visual Studio features (like debugging) or not.
0

Share this post


Link to post
Share on other sites
[quote name='Radikalizm' timestamp='1354942217' post='5008367']
I'd suggest using a different compiler if you want to use C++11 features, Visual Studio has some C++11 support but [b][i]it's severely lacking when compared to other compilers[/i][/b] like GCC.
[/quote]

That's not quite a fair statement, at least for VS2012 -- none of the current compilers have full C++ 11 support and each of them implement a different set, so some features might be implemented in one platform and the same feature might be missing from another. Also, some of the compilers that "support" a feature might offer partial support, or support in a way that's not perfectly standards-conforming.

In terms of overall support, the major compilers are not that far apart.

That said, VS lacks support for some of the cooler features like uniform initializers and variadic templates, for which other compilers offer at least some support.
-1

Share this post


Link to post
Share on other sites
[quote name='Ravyne' timestamp='1354956277' post='5008436']
That's not quite a fair statement, at least for VS2012 -- none of the current compilers have full C++ 11 support and each of them implement a different set, so some features might be implemented in one platform and the same feature might be missing from another. Also, some of the compilers that "support" a feature might offer partial support, or support in a way that's not perfectly standards-conforming.

In terms of overall support, the major compilers are not that far apart.

That said, VS lacks support for some of the cooler features like uniform initializers and variadic templates, for which other compilers offer at least some support.
[/quote]

I am doing cross platform development and MSVC is the only compiler that stops me using the C++11. I can use almost all parts of the standard with GCC, good luck with that with VC.

To be fair VS2012 had some basic support for C++11. November CTP added some more, but it doesn't update the STL and intellisense not working. So basically, it's [b]severely lacking[/b] compared to other compilers.
0

Share this post


Link to post
Share on other sites
[quote name='KingofNoobs' timestamp='1354951852' post='5008417']
Can one use the VC11 IDE with the GCC or other compilers?
[/quote]

See the vs-tool plugin in my signature if you want to try using MinGW or Clang from Visual Studio. There are also other plugins like that existing. Note however that the plugin is very experimental at this stage, so it can/may require some hacking and tweaking activities. Here's an example of what it looks like in action: https://dl.dropbox.com/u/40949268/code/vs-mingw.png
2

Share this post


Link to post
Share on other sites
A more objective comparison: [url="http://cpprocks.com/a-comparison-of-c11-language-support-in-vs2012-g-4-7-and-clang-3-1/"]http://cpprocks.com/a-comparison-of-c11-language-support-in-vs2012-g-4-7-and-clang-3-1/[/url]

Note that this comparison table doesn't count the November CTP.
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0