Thread: Stroustrup Talk on C++0x

  1. #1
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905

    Stroustrup Talk on C++0x

    Bjarne Stroustrup is visiting the University of Waterloo next week to talk about the new C++ standard, C++0x. He will be responding to questions at the end of the talk, so I am offering to ask a few questions in person for members of the CProgramming forums.

    Some research links for C++0x:
    http://en.wikipedia.org/wiki/C++0x
    http://www.research.att.com/~bs/rules.pdf
    http://www.artima.com/cppsource/cpp0x.html

  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Explicit override syntax
    In standard C++, derived classes override base class functions specified as virtual. Base classes must explicitly define a function as virtual in order for it to be so. However, derived classes are not required to use the keyword virtual for their overriding. Additionally, it is possible to misspell a function name, or use the wrong parameter list, which results not in overriding, but in the creation of a new function or overload by accident. Lastly, it is possible to introduce a new virtual function in a derived class, but the author of the base class introduces a new virtual function with the same name and signature in the base class at a later time, causing unusual behavior.

    C++0x fixes all of these problems. The derived class can be marked with the keyword explicit, which forces the derived class to be more specific about its intensions with regard to virtual functions:

    Code:
    class BaseClass
    {
      virtual void Func1();
      virtual void Func2(int);
    };
    
    class DerivedClass explicit : public BaseClass
    {
      virtual void Func1();         //Overrides BaseClass::Func1
      void Func2(int);              //Illegal. Must use keyword ''virtual'' for overrides
      new virtual void Func3(int);  //Introduces a new virtual function.
      virtual void Func4(float);    //Illegal. Must use keyword ''new'' for new virtuals
      virtual int Func2(int);       //Illegal. Signature does not match BaseClass::Func2;
    };
    This is a great idea. I've always wondered why the standard did not require all overrides in derived classes to use 'virtual.', since it requires the base to use virtual in order to make it a virtual function.


    Code:
    new virtual void Func3(int);  //Introduces a new virtual function.
    Not so sure I like the 'new' keyword being used as a prefix to a function declaration. That introduces some ambiguity on what it is that 'new' does. New in this instance is not truly allocating memory for a function. Even though all of us know that when we create a function the compiler must reserve memory at run time for the function using new like this is quite confusing. It is not the programmer who is actively reserving memory for a function as in the case of allocating space for an array or class object. So using new in this fashion really confuses the issue at hand and in my opinion does not follow with how new should be used. So basically we will have the same 'new' keyword but what that does will depend entirely on the context in which it is used in. If used prior to a virtual function in a derived class it will create a new virtual function. If used to allocate memory it will behave the same as 'new' has in past standards.
    I don't like this at all.

    Smart pointers?
    I did not see anything about smart pointers being a part of the new standard but I admit I did not read the all of the text so it might be in there. If not this disturbs me since boost has implemented several types of smart pointers and shared pointers. At the very least the C++ language could support it's own 'smart', 'shared', 'weak', etc, pointer types.




    Should we really have to use code tags inside of quote blocks?

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    The TR1 library already includes smart pointers (from boost's library) and C++0x will as well.

    http://en.wikipedia.org/wiki/C++0x#G...smart_pointers

  4. #4
    Ethernal Noob
    Join Date
    Nov 2001
    Posts
    1,901
    Will this manifest during the youth of my life.

  5. #5
    Massively Single Player AverageSoftware's Avatar
    Join Date
    May 2007
    Location
    Buffalo, NY
    Posts
    141
    Quote Originally Posted by indigo0086 View Post
    Will this manifest during the youth of my life.
    Given that it's actually called C++09 now, and not C++0x, yes it will, as long as you consider yourself young in 2009.

    The biggest part of C++09 is going to be the rvalue references. Those are a big big big deal. GCC 4.3 apparently has them implemented already, but 4.3 isn't released yet, and I lack the courage to try it.
    There is no greater sign that a computing technology is worthless than the association of the word "solution" with it.

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    New CodeWarrior versions have r-value references, too (they were the first, in fact), and I think Comeau also. And yes, they will be huge. I believe that they will fundamentally change the way we write interfaces.

    Not so sure I like the 'new' keyword being used as a prefix to a function declaration. That introduces some ambiguity on what it is that 'new' does.
    So they overloaded the keyword. Big deal. "virtual" has two meanings (related but clearly distinct), depending on whether it prefixes a function or a base class. "static" has three different meanings, depending on the scope of the variable/function declaration/definition it prefixes. "throw" has two meanings. "class" and "typename" both have two meanings. "const" has two meanings. "extern" has two meanings. Several other keywords can be used with slightly differing meanings in different contexts (e.g. while in a while vs a do-while loop). Operators are overloaded until they collapse. And C++09 will introduce additional overloads for both operators and existing keywords (auto, default, delete, explicit and new are those I know have been under consideration).

    At least the new meaning of new has something the others don't have: there's prior use of this (or a very similar) meaning in a different language, namely C#.

    So it's not like this is something exceptional.
    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

  7. #7
    Registered User
    Join Date
    Sep 2001
    Posts
    752
    Quote Originally Posted by AverageSoftware View Post
    Given that it's actually called C++09 now, and not C++0x, yes it will, as long as you consider yourself young in 2009.
    I'm still hoping it ticks over a year so we can get C++0A
    Callou collei we'll code the way
    Of prime numbers and pings!

  8. #8
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Quote Originally Posted by Bubba View Post
    So basically we will have the same 'new' keyword but what that does will depend entirely on the context in which it is used in. [...] I don't like this at all.
    The alternative would be to introduce another keyword and that's not something that they want to do. "explicit" is also used for somewhat different purposes now and we already have "static" from before. They only way they could've instroduced new keywords would've been like "_ _ keyword".

    I personally have absolutely no problem with ambiguity, because when I look at a class declaration I expect to see no memory allocation. There is no problem for a human here. The exception would be if you executed grep or something to see all lines where memory was allocated.
    Last edited by Sang-drax; 07-10-2007 at 01:59 PM.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  9. #9
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    They only way they could've instroduced new keywords would've been like "_ _ keyword".
    Not true. They're introducing quite a few new keywords. concept, concept_map, various others. But they're trying to keep the number low and not use a new keyword if an existing one is sufficient. And they're trying to use keywords that won't have a big effect on existing code. Code search engines are very useful for this.
    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

  10. #10
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Jeff! You're on campus now? I guess I'll see you at that talk! :P
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  11. #11
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    The talk was quite interesting. He clarified that it isn't yet C++09, but he hopes that it will become that (if not, C++0xA). He did mention the topic of smart pointers, but also mentioned that they do slightly worry him, given that they can cause coders to be sloppy, and think that that causes their pointers to be pretty much safe from any problems (such as race conditions, etc).

    Two concepts that he introduced that I really liked were the initializer list, which functions as follows (if I recall):
    Code:
    class foo
    {
    public:
      foo(std::initializer_list<int> Args);
    };
    
    ...
    
    foo a {1, 2, 3};
    foo b = foo{1, 2, 3};
    And also the concept of being able to assign traits to a template, i.e. state that your function takes a parameter that must support the preincrement operator (++foo) and the unary asterisk (*a) operator, etc.

    One other thing I just remembered is a new loop syntax:

    Code:
    vector<int> foo{1,2,3};
    ...
    for(const auto& e : foo)
    {
      ...
    }
    ...
    This causes e to iterate through all elements of the foo vector, and also causes the type of e to be the type associated with the foo vector (in this case, int).

    A couple other neat things such as regexs and threading/thread pools appear to be coming as well, but I can't remember details, as I just got back from taking Stroustrup out to a bar after his talk.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  12. #12
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,412
    This causes e to iterate through all elements of the foo vector, and also causes the type of e to be the type associated with the foo vector (in this case, int).
    Heheh, a for each loop after we have a for_each() algorithm.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  13. #13
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    But you have to admit the new for loop is so much prettier than the current for_each algorithm.

  14. #14
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    One of the things he emphasized in the talk is that they are putting effort in to making the language more accessible to novices. No, that doesn't mean we're going to have forced garbage collection and all objects are references *cringes* but we will be seing many things introduced that make sense.

    Building off of what XSquared noted, we'll finally see some clarity in template errors with the introduction of "requirements" on templated functions. This essentially seems to allow the programmer to inform compiler on what kind of functionality the function will require, giving room for the compiler to serve up errors before compiling the templated function (e.g. Error: your class requires the increment operator, as opposed to the confusing template errors we're all familiar with).

    He also briefly alluded to possibly cleaning up the syntax for function pointers (pointing out that even he finds them convoluted), such that returning a function pointer doesn't require the use of a typedef. This is something I think a lot of people will probably cheer about.

    And XSquared: the least you could have done was invite me over for some drinks when you two were at the pub. Sheesh.

  15. #15
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Actually, it was about 10 of us from the CSC (folks who ran the event) who ended up going out with Bjarne to the Bomber after the talk for about an hour. Really cool guy.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What one line unix talk combo generates the following....
    By Overworked_PhD in forum Tech Board
    Replies: 1
    Last Post: 01-20-2008, 08:48 AM
  2. US attack in Iraq (WAR Talk)
    By zahid in forum A Brief History of Cprogramming.com
    Replies: 298
    Last Post: 05-07-2003, 12:00 AM
  3. Interview with Bjarne Stroustrup "C++ a joke"
    By novacain in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 03-31-2003, 11:55 PM
  4. Who wants to talk on AIM?
    By Death Wish in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 07-05-2002, 06:29 AM