C++ Standard

16 Posts
1 2 Previous Next
0

Standards love to add things. They remove very little, but they do like to deprecate. This post will describe a collection of things that is heading that way, or not heading that way in C++ 0x.

In my posting on Intention to deprecate trigraphs in the next C++ Standard, we successfully demonstrated that much of the non-English speaking world will still need to rely on trigraphs as a way to get to UCN through "\" which may be inaccessible in some codepages. So we would object to deprecating it without an alternative.

In the last meeting in Santa Cruz, an alternative was proposed in Core issue 789:Replacing Trigraphs. In short, it does not so much deprecate trigraphs (which we like) as move trigraphs out of translation phase 1 so trigraphs are not recognized ahead of raw strings, but is still recognized ahead of other strings (as it is now). It seems that trigraph interaction with raw strings was always the real issue behind the original National Body comment. This interaction had become more prevalent because Raw strings are accepted as part of C++0x. This proposal will level the playing field to what it was again.

We reviewed the paper as a way of fixing the interaction of trigraphs and raw strings. We think the paper is ready to go, but we're holding it back because we're considering other approaches, including moving UCNs out of translation phase 1 or moving raw string recognition into phase 1.

We're still looking at deprecating exception specifications. Our current feeling is that we will deprecate them except for the ways of saying a function doesn't throw at all (e.g., the new noexcept feature, still being reviewed). This feature has been shown to be relatively useless since its inception.

We did a straw poll on deprecating or removing exported templates. I voted to support removal of export to reduce dialecting C++. However a straw poll in full committee seems to prefer deprecation. This feature has been implemented exactly by one company, and even their lead is not opposing its removal. We appreciate their selfless sense of the C++ community and appreciate their sacrifice in learning about why this feature was problematic. Sometimes, it does take doing to see the whole picture.

Finally, we deprecated the semantics of the register keyword. This keyword has been ignored by most compiler that I am aware of, so it is the right time to deprecate it.

As with all deprecation, have no fear. All compilers will generally continue to accept (and or ignore) these cases, so that your code will continue to compile.

0 Comments Permalink
0

The Library side brought about some of the most interesting changes. I already discussed the key discussions with respect to unifying the Asynchronous futures proposal in The View (or trip report) from the Oct 2009 C++ Standard meeting.

This resulted in a paper which will be published in the upcoming mailing (in about a week from now), which will show the approach on Asynchronous Call A Simple Asynchronous Call.

The key changes there were:

  • A restoration of the variadic thread and async functions. This restoration is a consequence of analysis and request of the British Standards Institute.
  • A convergence on the "as if a new thread" in the launching of asynchronous work. This change avoids undefined behavior arising from any delay in destroying thread-local variables, but requires careful implementation to avoid excessive overhead.
  • Removal of the is_ready, has_exception, and has_value query functions. The presence of these function requires still other functions in the synchronous case. Evolution Working Group direction is that the complexity in interface is as yet unjustified, and prudence dictates a smaller initial interface.
  • Unspecified behavior for the use of timed wait functions when the unique_future was created from a deferred async.
  • The conversion from unique_future to shared_future will execute any deferred work.
  • The use of an enum class to better clarify the launching policy.

The other papers which support this is a resolution of most of the futures issues from National Body comments in Issues on Futures (Rev. 1) . A future describes components that a C++ program can use to retrieve in one thread the result (value or exception) from a function that has run in another thread.

These components are not restricted to multi-threaded programs but can be useful in single-threaded programs as well.

The other resolved issues include:



  • moves swap from the <algorithm> header to <utility> to address UK 300 because swap has become a common utility operation with several common idioms relying on it




Most of these are motivated by National Body comments from CD1. This shows the effort and focus of the committee during these periods as we continue to resolve the almost 600 comments that was received from the September 2008 CD1 draft.

There is now plan to issue a second draft for comment (post removal of Concepts, and with the fixes like above from CD1 comments). This will be CD2 and will be aimed for release after the next meeting in March 2010, in Pittsburgh hosted by Carnegie Mellon.

I will describe in another post more details on the schedule changes which is now clearer and I have updated in the C/C++ Standard hub

0 Comments Permalink
0

Santa Cruz is a wonderful location for us to decide weighty matters such as how best to ship a C++ Standard with the overloaded number of issues. Normally a surfing town as I am told, I have not had a chance to even make it to the ocean shoreline as yet even though I am only mere blocks from it. So busy we are that let me waste no more time and recap.

1. P.J. Plauger (or Bill Plauger) has been the convener of the C++ meeting. There was an attempt to stop processing any new features in order to facilitate our promised shipping date for the Standard. The problem is what is new? Some issues are discovered late and are serious if not fixed. Some new issues are truly wish list and should be stopped. Other issues are somewhat in between but need to be weighted with all the other.

The vote that tried to stop all new feature failed probably because of how ambiguous the wording is, in my opinion. The issue isn't about stopping consideration of any new feature, but balancing all features based on their seriousness and only being able to handle a fixed number of them based on resource.

But the problem with that model of triage (which is often done in software industry), is that we are all volunteers and you just can't easily make volunteers do the hard thing, when they would rather do what they like.

The end result is that P.J. Plauger has tendered his resignation as convener. I and many would like to thank him for his service and his guidance which has enabled C++ meeting hostings well into 2011.

2. Both Evolution and Core Committees met in addition to Library. Evolution had to deal with a number of pending additions which had been long promised. The most significant discussion is the proposal to add Asynchronous and Futures to C++. This is a higher abstraction for concurrency that allows independent action with a return value.

This was controversial because there were two leading candidate proposals. The majority of the discussion allowed a unified proposal which offered:

  • A restoration of the variadic thread and async functions. This restoration is a consequence of analysis and request of the British Standards Institute.
  • A convergence on the "as if a new thread" in the launching of asynchronous work. This change avoids undefined behavior arising from any delay in destroying thread-local variables, but requires careful implementation to avoid excessive overhead.
  • Removal of the is_ready, has_exception, and has_value query functions. The presence of these function requires still other functions in the synchronous case. Evolution Working Group direction is that the complexity in interface is as yet unjustified, and prudence dictates a smaller initial interface.
  • Unspecified behavior for the use of timed wait functions when the unique_future was created from a deferred async.
  • The conversion from unique_future to shared_future will execute any deferred work.
  • The use of an enum class to better clarify the launching policy.

Interestingly, this discussion really only have bearing on two Library proposals which I will detail in a following blog post.


The formal motions for C++ Core language which resulted from this include the usual group of defect fixes, numbering into the 70 range. Basically, all Ready and Tentatively Ready issues of
n2962 except issues 799, 812, 861, 919, and 920.

There was also a paper called Reaching Scope of Lambda Expressions

n2998
Current lambdas restrict the referents of a lambda expression to the immediately-enclosing function or lambda expression. This restriction is severe and does damage to the utility of the lambda feature.

For example, a simple matrix multiplication kernal would require two enclosing scopes and there would be no captures. It is essentially equivalent to saying that the body of a nested loop cannot access function parameters.

Much of this is from the paper.

Consider the following function to multiply square matricies.


matrix operator*( const matrix& a, const matrix& b )
{
    int n = a.numrows();
    matrix c( n, n );
    for ( int i = 0; i < n; i++ ) {
        for ( int j = 0; j < n; j++ ) {
            double t = 0.0;
            for ( int k = 0; k < n; k++ ) {
                t += a[i][k] * b[k][j];
            }
            c[i][j] = t;
        }
    }
    return c;
}

Its rewrite into functions and lambdas, as intended by the adopted N2550, is as follows. Note that the rewrite is approximately the same size.


matrix operator*( const matrix& a, const matrix& b )
{
    int n = a.numrows();
    matrix c( n, n );
    for_range( 0, n-1, [&]( int i ){
        for_range( 0, n-1, [&]( int j ){
            double t = 0.0;
            for_range( 0, n-1, [&]( int k ){
                t += a[i][k] * b[k][j];
            } );
            c[i][j] = t;
        } );
    } );
    return c;
}

However this straightforward reformulation is ill-formed as per N2927 wording for 5.1.1 expr.prim.lambda paragraphs 9–12. To make the code well-formed, the function must be rewritten as follows, where inserted text shows new code, which sometimes alter variable references.

matrix operator*( const matrix& a, const matrix& b )
{
    int n = a.numrows( );
    matrix c( n, n );
    for_range( 0, n-1, [&]( int i ){
        const matrix& a1 = a;
        const matrix& b1 = b;
	int& n1 = n;
	matrix& c1 = c;
        for_range( 0, n1-1, [&]( int j ){
            const matrix& a2 = a1;
            const matrix& b2 = b1;
	    int& n2 = n1;
	    int& i2 = i;
            double t = 0.0;
            for_range( 0, n1-1, [&]( int k ){
                t += a2[i2][k] * b2[k][j];
            } );
            c1[i][j] = t;
        } );
    } );
    return c;
}

Such extensive mechanical editing will inhibit use, make errors more likely, and complicate code maintenance. Such editing is properly the domain of the compiler.

A third proposal n2989 "Unified Function Syntax" was not moved after significant discussion on whether it solved significant problem or not especially at this late stage, or just merely being a stylistic wish, especially if you have written large amounts of lambdas with the late specified return syntax and found current syntax ugly.

There was controversy because a previous proposal on auto lambda syntax was moved on the contingency that there would be room to explore a unified function syntax. However, as with all agreement in such a committee, the promise is always to allow the work to go forward with all the resource costs (such as authors and collaborators working together, review committee going over the proposal in this case over eight hours over several day), but there is no promise that it would be accepted. Such was the case, and of course the disappointment of the authors of this paper.

Well, in the next posting I will go over the Library proposal.

0 Comments Permalink
0

I am attending the C++ Standard meeting in Santa Cruz. We have a number of issues of interest to us.

SCARY iterators is a way to improve portability invented by our IBM Watson Lab and collaborated on with testing using the xlC++ compiler. It also can give significant performance gains, especially in Blue Gene software:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2913.pdf

The other issue of interest is continuing discussion on resolution to the Trigraph deprecation issue. Although the idea of deprecation was rejected in Frankfurt, there was a desire to reach a common solution by replacing trigraph with something else. A paper was produced and we will review it in the next meeting:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2978.pdf

The solution will resolve many of the issues in my previous posts about trigraphs but we do have some comments. On the whole, we are pleased with this compromise approach.

The other issues that will be discussed will be how to control the proliferation of issues that could cause a prolonged delay of publication of the Standard.

Like any software delivery, shipping a Standard meets the same problems in that there will be many late issues come up out of integration and testing. Some of those will be new, while others are critical fixes. All issues need to be considered fairly through a triage process to see whether they are critical enough to require fixing before shipping, or can afford to be delayed until post-shipping.

This process as obvious as it is to do is not something that is easy to do at the Standard level where work is voluntary. There will be repercussion to this as we move forward if we do not adequately resolve this.

0 Comments Permalink
0

One of the issue we were concerned about at this meeting was the intent to deprecate trigraphs. We wrote a paper indicating why we oppose this. This was reviewed in the Evolution Committee and many delegates accepted our position and need to support existing customers. This is good for existing trigraph users.

However, discussion in committee indicate that if we can find an alternate way to support these users then we should explore that with the blessing of the committee. I will be looking at alternatives in future postings.

The C++ Standard Library Working Group also ratified four proposals into the C++0x draft.

C++0x Stream Positioning

C/C++ I/O files predates modern file sizes, and are usually based on int or long. This proposal allows them to work better with the new long long type in C++0x.

Specifying the complexity of size() (Revision 1)

This paper addresses the issue of testing size() and not knowing their complexity constraint. This makes it difficult to use containers where testing size is a frequent operation.

Thread Unsafe Standard Functions

This paper does not make C++ Standard functions thread unsafe, despite the name. Its intention is to clearly identify functions adopted from the C standard that need explicit exemption from the general prohibition on data races.

For example, these are already exempt:
asctime, ctime, gmtime, localtime, strerror, strtok, rand,

The following functions may have previously been thread unsafe, but must be thread safe to enable effective programming. By failng to mention these functions, the standard implicitly requires them to be thread safe.

atexit, at_quick_exit, exit, fclose, free, quick_exit, malloc, signal

Furthermore, C++ locale objects are already adequate for thread-safe locales; setlocale() is thread-unsafe.

Fixing freestanding: iteration 2.2

A freestanding platform is one that has an Operating System. This proposal aims to:
· enable the intent of the freestanding specification compliance to be preserved, by adding only two headers to it relative to its C++98/C++03 contents, namely <initializer_list> and
<type_traits>
· maintain the historically low dependency of the C++ language, and of C++ compilers, on a corresponding library

The benefits of this proposal are:
· it enables current users of the freestanding specification to continue using that specification
· it enables compiler implementers to work fairly independently of library supply
· it enables library implementers to work fairly independently of compiler supply

0 Comments Permalink
0

Hello all, we are here in Frankfurt as part of the Canadian delegation. This is a momentous meeting.

At this meeting, Concepts, the major feature of C++ 0x, which enables constrained genericity, or template argument prototyping, has been removed from the C++0x draft.

The reason this is big is because many people have worked on this for over 6 years, and it is probably one of the poster child feature for C++0x. Aside from this, Garbage Collection was also removed early in the process, because of fears of its complexity implications. These two features integrate pervasively into almost every area of the standard, are not orthogonal, and have many legacy impacts. The only other major feature that remain, because it has to is concurrency. This last one appears safe, at least.

The reasons for questioning Concepts at this point can be best described by a paper by Bjarne Stroustrup simply called "Simplifying the use of Concepts":

Simplifying the use of Concepts

Bjarne feels that this is a major setback and some feel that this could be patched. Our next chance could be about 5 years, because now it is a redesign, and it is questionable whether the usability, and implementation issues will really be solved.

In the mean time, there will be implications as we make a major change to the latest C++0x draft, likely issue it out for another Committee Draft and National Body Comment. Features that have been accepted since most of Concept entered in the September, 2008 San Francisco meeting may have to be reviewed as they get stripped of Concepts.

Enough about Concepts as I am sure this will not be the last we will hear of it. Lets move on to other things that we have accomplished in this meeting.

1. We plane to submit the Decimal Technical Report to ISO for Technical Report Ballot. This is an important process goal because it enables a specification for using base-10 as the basis for computations, instead of base-2 as we have been using, and continue to use.

Decimal Technical Report

2. For Core language changes, we accepted a number of new papers. The links do not work until the papers are posted about 2 weeks from now.

New wording for C++0x Lambdas (rev. 2)

This paper rewords all of the lambda sections which originally had inadequate wording and examples.

Implicitly-Deleted Special Member Functions.

Now that we have removed concepts, some good things that were brought in by concepts should not be thrown out with the bathwater. This intent of this feature is to ensure that template argument deduction fails when it finds an implicitly-declared special
member function whose definition would fail to compile. The problem came up in the context of concepts, where the
type std::pair<const int, int> was getting an implicitly-declared copy-assignment operator, such that it met the
requirements of the CopyAssignable concept. However, the definition of the copy-assignment operator is ill-formed
(due to the const member), causing unexpected failures. By making this copy-assignment operator deleted, it can no
longer be used to satisfy the requirements of the CopyAssignable concept. Even without concepts, this issue still
comes up with the extended SFINAE rules.

Range-Based For Loop Wording (Without Concepts)

This is another one of those feature that has to be readjusted because of the loss of Concepts. Specifically, range-based for statements will be using argument-dependent lookup of begin and end (which always includes those begin and end functions in namespace std) to provide the iterator to the beginning and ending of the sequence. Specify range-based for statements so that arrays and initializer lists have no dependencies on <iterator>. Refactor <initializer_list> so that it as no dependencies on other headers and includes no other headers.
Specify the library headers that are to #include <initializer_list>.

Pack expansion and attributes (rev. 2)

The aligned_union template in the library was intended to provide simple support for union-like types whose elements may support non-trivial constructors and destructors. When this support was added directly into the language the library template was deemed superfluous, and removed. (This was a TR1 extension, so there are no back-compatibility issues).

However, it has emerged that there remains at least one use case for the feature. When trying to create a 'discriminated union' template using variadic templates, it is not possible to to declare the members of the union via a pack-expansion. This requires a fall-back on an aligned_union like utility.

This would be significantly easier to write if the [align] attribute supported a pack-expansion to return the strictest alignment. This feature is already supported if the types are listed individually, but the grammar does not yet support pack expansion within an attribute. This is seen as the motivating example to extend the attribute grammar to support pack expansion, where the named attribute explicitly documents support.

Explicit Virtual Overrides

We would like to tighten the rules for overriding virtual functions, to detect these problems:

* a base class B has a virtual function f, and the user declares their own f in derived class D, thereby accidentally overriding B::f.
* a base class B has a virtual function f, and the user wishes to override that function in the derived class D, but misspells the name as D::foo.
* a base class B has a virtual function f, and the user wishes to override that function in the derived class D, but inadvertently alters the parameter list.

We are deliberately not solving the problem that a base class B1 has a virtual function f, another base class B2 also has a virtual function f with the same signature, the user derives a class D from both B1 and B2 and declares D::f to override both B1::f and B2::f, one of which may have been inadvertent. (This is sometimes referred to as the Siamese Twins problem.)

The scope of the problem was reduced to the minimal necessary to solve the common real-world problems. This means it does not tackle ideas such as 'final overriders' or function renaming, both of which would be available if a scheme closer to the C++/CLI standard was pursued.

There are also library papers which have been approved. I will describe that in the next posting.

0 Comments Permalink
0

On July 20, I will be giving a talk at Aachen University jointly with Forschungszentrum Jülich GmbH where we have our JUGENE Supercomputer, at the invitation of Christian Terboven, a research associate, whose blog I read regularly:
http://terboven.wordpress.com/

This will be a 3 hour talk to cover the latest updates from the C++ Standard Committee (and there are many) and C++0x Concurrency. Here is the poster:

http://www-949.ibm.com/software/rational/cafe/servlet/JiveServlet/imagePreview/1670/75-75/aachenjulichabstract.pdf

Aachen University carries a large IBM backup / archive solution and are using IBM Tivoli Identity Manager software throughout the whole university (and were the first in the whole world to do that).

For those curious about JUGENE, this is gathered from wikipedia entry.
This is a BlueGene/P with 65,536 PowerPC 450 cores, clocked at 850 MHz and housed in 16 cabinets the computer reaches a peak processing power of 222.8 TFLOPS (Rpeak). With an official Linpack rating of 167.3 TFLOPS (Rmax) JUGENE took second place overall and is the fastest civil/commercially used computer in the TOP500 list of November 2007.

In February 2009 it was announced that JUGENE wil be upgraded to reach petaflops performance in June 2009, making it the first petascale supercomputer in Europe.

On May 26, 2009, the newly configurated JUGENE was unveiled. It includes 294 912 processor cores, 144 terabyte memory, 6 petabyte storage in 72 racks. With a peak performance of about one PetaFLOPS, it is the third fastest supercomputer in the world, ranking only behind IBM Roadrunner and Jaguar. The new configuaration also incorporates a new water cooling system that will reduce the cooling cost substantially.

0 Comments Permalink
0

The mailing for the July C++ Standard meeting has been released. For those who do not understand this process, this is basically where everyone writes up their work for the upcoming meeting so we have something concrete to discuss.

IBM has submitted 2 papers. One is a direct response to the proposed trigraph deprecation as discussed here:

http://www-949.ibm.com/software/rational/cafe/thread/2293?tstart=0
and
http://www-949.ibm.com/software/rational/cafe/blogs/cpp-standard/2009/06/03/intention-to-deprecate-trigraphs-in-the-next-c-standard

are posed in these papers:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2910.pdf

We have also submitted a paper based on IBM research:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2911.pdf

on how to improve compatibility between C++ library implementations for C++ iterators:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2913.pdf

I will say more on these papers in a future blog.

0 Comments Permalink
0

Do you use trigraphs?
If so, you may be interested that the C++ Standard Committee will vote to deprecate trigraphs (to Appendix D) in the next meeting in July 12-18 in Frankfurt as I discussed in my last trip report:
http://www-949.ibm.com/software/rational/cafe/blogs/cpp-standard/2009/05/27/the-view-or-trip-report-from-the-mar-2009-c-standard-meeting

Trigraph sequences are

??= # pound sign
??( [ left bracket
??) ] right bracket
??< { left brace
??> } right brace
??/ \ backslash
??’ ^ caret
??! | vertical bar
??- ~ tilde

One of the reason they were invented was because a character like '#' have code points that differ across EBCDIC code pages.
It is safe to use '?' and '=' because these share the same code point across all EBCDIC code pages.
Another reason is that on some international keybaords, these characters do not have representation and they must be typed in using this sequence of text. They get replaced in quotes because they are handled in phase 1 of translation and can be replaced even if found inside another token, such as a quoted string, or character constant.

There are some possible alternatives. Digraph supply a subset of trigraphs:


%: or %% # number sign
<: [ left bracket
:> ] right bracket
<% { left brace
%> } right brace
%:%: or %%%% ## token pasting


But it does not represent these trigraphs and cannot be a complete replacement:
??! |
??' ^
??/ \
??- ~

Digraphs also are handled during tokenization and must always be a full token by itself. This means it will not be replaced inside quotes.

Now you can use something like an alternative spelling for operators to cover 3 of those 4 cases:
bitor
or
or_eq
xor
xor_eq
compl

But one of those four, '\' truly has no replacement possibility.

Even in the ASCII world, the loss of trigraphs can be problematic if a keyboard does not have backslash. Does this happen? I would like to know.
Loss of backslash also can lead to other characters that are variant, including the half-width backslash in Japanese, and the yen sign in Shift-JIS.

So why is there enthusiasm for this deprecation?

It is precisely because of the ability to replace trigraphs in quotes. They can look like question marks, and in some cases they are especially when inside a quoted string. There is cause for confusion. Specifically, one National Body comment urge the removal of trigraphs because:
'Trigraphs are a complicated solution to an old problem, that cause more problems than they solve in the modern environment. Unexpected trigraphs in string literals and occasionally in comments can be very confusing for the non-expert. "

Are there others, I would like to know. Some folks have mentioned how this can be a problem is modern Perl searches.

I would be interested if you agree with these statements and what opinion you may have on the deprecation of trigraphs.

0 Comments Permalink
2

Hi, all. I apologize for the lack of updates as an addition to the family has kept me hopping. But just as important is where is the C++ Standard, so here is the long delayed trip report.

The C++ Meeting in Summit, NJ on Mar 1-6 was the first meeting we had after the draft release for public comment of the C++ 0x Standard. In this meeting, we addressed the various National Body comments based on the draft that was released in the September San Francisco meeting.

A list of the National Body Comments can be found here:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2837.pdf

Out of these National Body Comments, there were:

National Body Comments Unresolved Accepted Modified Rejected Total
Core Language 93 32 8 43 176
Library 128 36 5 35 204
Editorial 28 148 14 21 211
Total 249 216 27 99 591


As a rough count, there are :

  • Language
    • 70 features
    • 300 defects ( in the C++ Standard)
  • Runtime
    • 70 features
    • 230 defects ( in the C++ Standard)

That is a lot of features and a lot of defects. Not all the defects will be in every compiler, because some defects are just textual changes. Almost every compiler I know of will be doing a phased released approach, delivering all these across multiple releases.

One unnamed compiler vendor I spoke to at the recent BoostCon09 joked that it may not be all delivered until 2020. I didn't think he was joking, on reflection.

While I am on BoostCon09, I did a 90 minute talk on the Overview of C++0x and compiler support. The external trip report for that talk can be referenced here:
http://par-con.blogspot.com/
and here:
http://revergestudios.com/reblog/index.php?n=ReCode.BoostCon09
My trip report is here:
http://www-949.ibm.com/software/rational/cafe/blogs/ccpp-parallel-multicore/2009/05/25/the-view-trip-report-from-boostcon09
The video of the talk will be online soon.

From my point of view, the other significant thing that happened was a total rewrite of the section on lambdas. The CD1 version of lambda, a significant feature had no examples at all, and did not deal with many, many edge cases (such as how are arrays passed). This section and its design was discussed carefully and a new section will appear in the next draft, which will address many of these problems.

Another interesting discussion is the intent to deprecate various potentially unused C++ entities. These include the meaning of the register keyword, and trigraphs.

On the register keyword, the intent is to deprecate the meaning of the keyword, which used to be that variables qualified as register may be allocated to a register, at the discretion of the compiler. With today's sophisticated register allocator, this advice is rarely taken anyway, and the compiler often would make independent decision based on an abstract machine with a register file that is far greater then what is normally present.

The deprecation of this meaning is welcomed. The keyword will remain for use by for some future meaning.

On the deprecation of trigraphs, the thought process is that there is concern about the confusion when trigraphs are used in quotes with normal usages of question marks, since trigraphs often start with multiple question marks. This one is more problematic from my point of view as it is not clear how their use will be substitutable on international keyboards where such code pages are not present or is represented differently. It does not seem digraphs will replace all the pieces. I will describe more on this in a future post.

The latest draft as of May 25, 2009 is:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2857.pdf

You can get a really good idea of what is in the 0x CD1, that is different from the C++98/03 draft in this excellent document by Alisdair Meredith. I have not reviewed it for completeness, but it is a great resource:

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2871.html

Bye for now, and I will post again real soon.

2 Comments Permalink
0

The next C++ Standard meeting is rapidly approaching. This meeting will be the first meeting after the Committee Draft (CD) for C++0x was released last year in September. A CD is like an alpha of the C++ Standard.

Since then, there has been one update to the CD in December with minor fixes:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2800.pdf

This will be the first meeting where we will process defects, and National body comments. Most people will be watching for any show stoppers which can cause a delay to the proposed schedule of the C++ Std as outlined at the right side panel of this blog.
http://www-949.ibm.com/software/rational/cafe/community/ccpp/standards

So far, from watching the discussion on the reflector, there has not been any major of note. But that does not preclude them from being discovered as we work through the comments and defects.

The C++ Std meeting is open to anyone, and if you are in the Summit New Jersey area (specifically Grand Summit Hotel), and is interested in contributing to the Standardization process, please drop by. But first you need to notify the convener. I can help with that.

As usual, IBM will be sending two representatives to this meeting. Both of us will represent the Canadian delegation.

0 Comments Permalink
6

Mysteries of Namespaces

Posted by Michael_Wong Feb 10, 2009

There are few features added in the last C++98 standardization that caused nearly all earlier C++ code to break. One is the addition of namespace and the moving of almost all of the C++ Standard library into it. Can you name a few examples that were not moved into standard namespace? This is the first Mystery of the Month.

Yet, used in its simplest way, namespaces are basically benign. A namespace is a subdivision of global scope. But even basic namespace as they are come with gotchas, which I will show in this discussion.

Next, we will take a closer look at using directives and declarations.

There are a number of key differences between these two. What are they and can you figure it out from the way this code behaves:

#include <vector>

int main()
{
using namespace std; //a using directive
int vector=99;
vector<int> x; 

}


and this
#include <vector>

int main()
{
using std::vector; //a using declaration
int vector=99;
vector<int> x; 

}


Call this the second Mystery of the Month. What is this code telling us about the real nature of these two kinds of usings (specifically, about where they are actually declared)?

Knowing this, it saids something about their usage style too. IN fact, is it really a good choice to use them the way I have,

1. inside a function body or
2. should I place them at file scope ahead of the include or
3. should I place them at file scope after the include or
4. should I place them in a header file

This is mystery number 3. Where should they be used and this one is necessarily somewhat subjective in one of the choice, but one is clearly evil. You just need to defend your choices.

6 Comments Permalink
8

Something that Java, C++/CLI, and C# already has, is called delegating constructor. This is the ability for one constructor to delegate to another within the same class.C++03 does not have this capability because you cannot name a constructor within the same class in one of its constructor's initializer list. It can use constructors of other class types, including base classes and member objects.

In fact, it causes a serious problem when people who learn these other language come to C++, and try using it because what looks reasonable, will compile and run, but does not do what they think it does.

And it is more common then you think, because in many cases constructors may differ by the parameter list with common bodies. If the constructor can use default arguments, you could common the bodies. If it can't then you are out of luck today:

class A {};//has a conversion operator to double
class C
{
int x;
double y;
void startup();
public:
 //C(): x(0), y(1.23) { startup();} // I can collapse this into the following constructor and common up the body
 C(int i=0) : x(i), y(1.23) { startup();}
 C (const A& a) : x(0), y(a) {startup();} // I can't with this one
};


So having successfully refactored once, you might decide to try it in another case, turning this code into:
class X {
  Y y_;
  Z z_;
  void init();
public:
  X() { init() };
  X( int i ) : y_( i ),z_(1.23) { init(); }
  X( Widget w): y_(3.21), z_(1.23) { init(); }
};


this because this is similar to Java delegating constructors:

class X {
  Y y_;
  Z z_;
  void init();
public:
  X(){ init(); };
  X( int i ) : y_( i ),z_(1.23) { X(); }//I know both constructors are run because I can see it in a debugger
  X( Widget w): y_(3.21), z_(1.23) { X(); } //same here
};


This should work. Or should it ?

Well of course it doesn't, and the Mystery#1 of the Week is can someone tell me why not?

So may be we want to try something even more ambitious:

class X {
  Y y_;
  Z z_;
  void init();
  void *operator new(unsigned int, const X*);
  ... //assume we also have corresponding delete
public:
  X(){ init(); };
  X( int i ) : y_( i ),z_(1.23) { new (this) X; }//I know both constructors are run because I can see it in a debugger
  X( Widget w): y_(3.21), z_(w) { new (this) X; } // Same here
};


This looks even more promising and in fact it does everything I want it to do. Seems clever as I am using a placement new on the same object. In reality, it is an even worst solution then before. Mystery#2 of the Week is why is this worst?

In fact C++03 had no better solution which is either more cumbersome, or error prone.

C++0x will fix this for the sake of improved teachability and library building. The solution is to simply allow the call to the target constructor in the initializer list of the delegating constructor. We call the caller the delegating constructor and the callee is the target constructor

class X {
  Y y_;
  Z z_;
  void init();
public:
  X( int i, const Widget &w): y_(i),z_(w) { init();}
  X(){ init(); };
  X( int i ) : X( i, 1.23) {  }
  X( Widget w): X(3.21, w) {  }
};


The final accepted paper is in:
n1986

8 Comments Permalink
0

Hi, I had the honor and pleasure of being invited to visit Professor Bjarne Stroustrup at Texas A & M University yesterday, delivering a talk on C++ in OpenMP:

http://parasol.tamu.edu/seminar/abstract.php?talk_id=586

I will say something more about this subject in the Parallel Computing blog. But I am interested in announcing something that Bjarne shared with me while I was in his office. This is a new C++0x FAQ which he is preparing on this page:

http://www.research.att.com/~bs/C++0xFAQ.html

I will put this link up as a permanent link on the front of this hub.

0 Comments Permalink
2

The Dawn of a new Standard

Posted by Michael_Wong Nov 18, 2008

We live in interesting times.

At no times is this more true then today's C++ as we move towards a new
Standard code named C++0x, to be released, tentatively 2009.

But x could be A, B, C, D, E, F ?:|

Hi, my name is Michael Wong. I am the Canadian C++ Standard
representative for evolution and language. Robert Klarer is the representative for
library. We would like to invite you to watch this blog for discussion on C++ Standard
happenings. We will use this space to file trip reports on the C++
Standard meetings, as well as interesting happenings in the C++ community.

With loads of new features in C++0x, such as Concepts, Concurrency,
move semantics, auto type inference, new initialization syntax, C++0x
will be promising big things. Can it deliver?

But that is not all. C++ has gone through a renaisance of ideas with
the support of Generic Programming, metaprogramming, and Boost
Libraries. How about functional programming, domain-specific languages or garbage collection?

So come back regularly, and watch the story as it develops.

Thanks.

2 Comments Permalink
1 2 Previous Next

C++ Standard

Bottom Banner