![]() | This article is rated Start-class on Wikipedia's
content assessment scale. It is of interest to the following WikiProjects: | |||||||||||||||||
|
|
Although I did not agree with 71.85.145.203 just replacing the entire article with a simple example, it does beg the question, why not include an example (identifying the language used of course). For example, 71.85.145.203's C example is:
- public void setJobTitle(String jobTitleIn) {
- jobTitle=jobTitleIn;
- }
I haven't written any software since C++ came out (when "Hello world!" coding went from 4 lines to 4 pages :-) but if this is a reasonable example, and we are in agreement in regard to adding an example, would someone add an example section in the article and drop this (or something better if you like) in there? cheers, JimScott 22:48, 20 November 2006 (UTC)
What about this?
#include <stdio.h> void f(void) { puts("in f."); } void g(void) { puts("in g."); return f(); } int main(void) { g(); return 0; }
It compiles on gcc (last time I checked), and it works as expected. Should it? Degenerate case? -- 92.229.73.235 ( talk) 07:05, 8 March 2010 (UTC)
“C and C++ also support the pointer to void type (specified as void *), but this is an unrelated notion. Variables of this type are pointers to data of an unspecified type, so in this context (but not the others) void acts as a universal or top type.” That is not true, under many circumstances it acts like a top type, but you cannot instantiate variables of the type void or allocate voids:
void foo() { (void)12; return 5; }
(valid C++) How should that be reformulated? -- Chricho ∀ ( talk) 21:51, 10 March 2011 (UTC)
This is the same explanation I see everywhere and I can't imagine what its supposed to mean. "The void type, " ...", is the type for the result of a function that does not return a result." A result that doesn't return a result? Doesn't return it where? Is this sentence supposed to be implying that a void-type-method is "a method which doesn't include the 'return' command"? I suggest a better opening sentence, one that explains the meaning better, rather than leaving so many unanswered questions. —Preceding unsigned comment added by 72.187.99.79 ( talk) 18:56, 4 April 2011 (UTC)
How about adding some information about void type vs. generic class or function (procedure)?
For example:
t voidTypeExample<t>() {
}
Since OOP languages aren't so flexible with working with pointers.
Galzigler ( talk) 19:55, 12 March 2012 (UTC)
You cannot pass "any data" type to a function with this signature because it might trigger undefined behavior and crash at runtime i.e. to call f with a std::string as parameter. -- RokerHRO ( talk) 14:11, 23 July 2012 (UTC)
No. Such class type arguments are conditionally-supported with implementation-defined semantics since C++11. Other types may be ill-formed, but not UB. -- 幻の上帝 ( talk) 08:00, 5 January 2016 (UTC)
The introduction says: (...) the void type is taken to be an empty type with no values.
In Algol 68, the VOID type has one value. It even has a denotation: EMPTY. Rp ( talk) 14:16, 15 January 2013 (UTC)
![]() | This article is rated Start-class on Wikipedia's
content assessment scale. It is of interest to the following WikiProjects: | |||||||||||||||||
|
|
Although I did not agree with 71.85.145.203 just replacing the entire article with a simple example, it does beg the question, why not include an example (identifying the language used of course). For example, 71.85.145.203's C example is:
- public void setJobTitle(String jobTitleIn) {
- jobTitle=jobTitleIn;
- }
I haven't written any software since C++ came out (when "Hello world!" coding went from 4 lines to 4 pages :-) but if this is a reasonable example, and we are in agreement in regard to adding an example, would someone add an example section in the article and drop this (or something better if you like) in there? cheers, JimScott 22:48, 20 November 2006 (UTC)
What about this?
#include <stdio.h> void f(void) { puts("in f."); } void g(void) { puts("in g."); return f(); } int main(void) { g(); return 0; }
It compiles on gcc (last time I checked), and it works as expected. Should it? Degenerate case? -- 92.229.73.235 ( talk) 07:05, 8 March 2010 (UTC)
“C and C++ also support the pointer to void type (specified as void *), but this is an unrelated notion. Variables of this type are pointers to data of an unspecified type, so in this context (but not the others) void acts as a universal or top type.” That is not true, under many circumstances it acts like a top type, but you cannot instantiate variables of the type void or allocate voids:
void foo() { (void)12; return 5; }
(valid C++) How should that be reformulated? -- Chricho ∀ ( talk) 21:51, 10 March 2011 (UTC)
This is the same explanation I see everywhere and I can't imagine what its supposed to mean. "The void type, " ...", is the type for the result of a function that does not return a result." A result that doesn't return a result? Doesn't return it where? Is this sentence supposed to be implying that a void-type-method is "a method which doesn't include the 'return' command"? I suggest a better opening sentence, one that explains the meaning better, rather than leaving so many unanswered questions. —Preceding unsigned comment added by 72.187.99.79 ( talk) 18:56, 4 April 2011 (UTC)
How about adding some information about void type vs. generic class or function (procedure)?
For example:
t voidTypeExample<t>() {
}
Since OOP languages aren't so flexible with working with pointers.
Galzigler ( talk) 19:55, 12 March 2012 (UTC)
You cannot pass "any data" type to a function with this signature because it might trigger undefined behavior and crash at runtime i.e. to call f with a std::string as parameter. -- RokerHRO ( talk) 14:11, 23 July 2012 (UTC)
No. Such class type arguments are conditionally-supported with implementation-defined semantics since C++11. Other types may be ill-formed, but not UB. -- 幻の上帝 ( talk) 08:00, 5 January 2016 (UTC)
The introduction says: (...) the void type is taken to be an empty type with no values.
In Algol 68, the VOID type has one value. It even has a denotation: EMPTY. Rp ( talk) 14:16, 15 January 2013 (UTC)