Return Void - ... (*pf)(); return; } Once you start playing...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Return Void Jonathan Schilling, jls@sco.com One issue that the C++ standards committee has discussed several times is allowing the return statement to return expressions of type void. An example would be this: void m(); void n() { return m(); } Currently, this is not allowed; the proposal is to extend the language to allow a return statement to have an expression of void type, within a function of void return type. The motivation is to make it easier to write templates. Consider this example, which in a different form appears in the new standard library: template <class T> T f(T (*pf)()) { ... return pf(); } int g(); void h(); ... f(g); // currently allowed f(h); // currently an error, proposed to be allowed Without the extension to the language, a template specialization would have to be provided for the void case: template<> void f(void (*pf)()) {
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ... (*pf)(); return; } Once you start playing with extensions involving void, there's a temptation to go further toward making void a first-class type. Doing this might ease template writing in other contexts, but the effort quickly runs into language definitional problems. The argument for this limited extension is that it isn't really an introduction of void objects or void arguments, but rather a realization that the currently allowed: return ; already has an implicitly void expression in it. While this proposal has not yet been formally adopted (the standard is currently in a review and balloting phase and actual changes to the working paper cannot be made), it received widespread support at the recent Nashua meeting and is likely to be voted in at the next meeting this summer....
View Full Document

This note was uploaded on 02/27/2012 for the course CS 251 taught by Professor Staff during the Fall '08 term at Purdue University-West Lafayette.

Page1 / 2

Return Void - ... (*pf)(); return; } Once you start playing...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online