Thread: C++0x

  1. #1
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034

    Red face C++0x

    How do you get lamdas/etc to compile under the latest TDM in Code::Blocks?

    Code:
    #include <string>
    
    int main()
    {
        auto s = []()
        {
            std::string("hello world");
        };
    }
    In function 'int main()':
    error: expected primary-expression before '[' token
    error: expected primary-expression before ']' token
    error: unable to deduce 'auto' from '<expression error>'
    error: expected ',' or ';' before '{' token
    === Build finished: 4 errors, 0 warnings ===
    I tried compiler settings -std=gnu++0x and -std=c++0x. That's what Google said. Neither worked. Thanks :]
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    GCC doesn't support lambdas yet.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    I haven't played with C++0x yet, but if it can deduce the type as an array you can do:

    Code:
    int main()
    {
        auto s = 
        {
            std::string("hello world");
        };
    }
    Otherwise, I guess it would be:

    Code:
    int main()
    {
        auto s [] = 
        {
            std::string("hello world");
        };
    }
    I don't know much about arrays and the auto keyword, but one of the two should work.

  4. #4
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    lol Sebastiani, it's not an array, it's the new lambda syntax.

    Quote Originally Posted by CornedBee View Post
    GCC doesn't support lambdas yet.
    Edit: Oops, it's just intel / gcc 4.4.1 - http://software.intel.com/en-us/blog...-lambdas-in-c/

    Oh well, thanks.
    Last edited by Dae; 08-27-2009 at 06:36 AM.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  5. #5
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Quote Originally Posted by Dae View Post
    lol Sebastiani, it's not an array, it's the new lambda syntax.



    I google'd a few forums which imply otherwise (gcc 4.4) and this (gcc 4.4.1 - the comment):

    Intel Software Network Blogs » “Hello Lambdas” C++ 0x, a quick guide to Lambdas in C++

    Oh well, thanks.
    Oh, I see. That makes more sense.

  6. #6
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    I'm not sure if this is 100% C++0x compliant, but it looks promising.

  7. #7
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Quote Originally Posted by Sebastiani View Post
    I'm not sure if this is 100% C++0x compliant, but it looks promising.
    That would be the "latest TDM" I mentioned in the OP. It looks good for sure, it's even up to date, unfortunately as CornedBee said GCC (I think he meant to specify GNU GCC) doesn't support lambda's yet.. Forgot about the progress page:

    C++0x Support in GCC - GNU Project - Free Software Foundation (FSF)

    Anyway, I keep reading suspicions of bloated filesizes, cpu usage, seg faults, and lack of popular library support for c++0x. It still looks decent, but I'll wait. I wonder if switching for just the auto keyword would cause any problems or be a bad choice :P
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  8. #8
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Anyway, I keep reading suspicions of bloated filesizes, cpu usage, seg faults, and lack of popular library support for c++0x.
    Sounds completely nonsensical. Sure, you might get compiler segfaults in the experimental parts, but other than that ...
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  9. #9
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Quote Originally Posted by CornedBee View Post
    Sounds completely nonsensical. Sure, you might get compiler segfaults in the experimental parts, but other than that ...
    Nonsensical or not, that's just what I've read on mailing lists. How much of it is actually complete? Look at the list. At quarter of what's actually completed looks experimental. You've got to figure writing any decent sized script you're going to run into it sooner or later. The question is how long you'll be waiting for a bugfix, or converting all your code to use an older method. So you think it's worth switching? Disregarding tr1, just renamed boost.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  10. #10
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    The C++0x standard isn't finalized, so there's nothing wrong with these features being experimental. I wouldn't use them in production code yet, but mostly because I worry about cross-compiler portability.
    However, the way compilers work, it's very unlikely that any of the C++0x features, except perhaps the multithreading stuff - leads to real miscompilations, where the resulting program crashes at runtime or is extremely slow.
    The library features are a different matter. They are, like any new code, subject to bugs.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  11. #11
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Some features are set in stone and is finalized, though. Lambdas and auto would be two of them. Otherwise compiler vendors wouldn't have attempted to implement any of it for a release.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed