Topic: Void Usages
Author: tinct@163.com (Tinct)
Date: Wed, 26 Sep 2001 17:04:35 GMT Raw View
The Book "The C++ programing language" (7.3) says that a void function
can use a call of a void function as the expression in return
statement.
void f(void);
void g(void){ ... return f(); } //ok
So, I tried some "void" usage and the result is: ( BCC 5 )
f(),g(),1,void("TEST"),2; // ok
f(()); // error #1
f(void); // error #2
f(g()); // error #3
f( (g(),g()) ); //error #4
So, it means "void" is a very special type in c++ and the only way to
call a f(void) is f(). #1~#4 might be useful in template or marco. I
don't know. It is only a test for void usage.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: Attila Feher <Attila.Feher@lmf.ericsson.se>
Date: Wed, 26 Sep 2001 18:04:43 GMT Raw View
Tinct wrote:
>
> The Book "The C++ programing language" (7.3) says that a void function
> can use a call of a void function as the expression in return
> statement.
> void f(void);
> void g(void){ ... return f(); } //ok
[SNIP]
> So, it means "void" is a very special type in c++ and the only way to
It is very special. The only way you can "use" a void is in the return
as you saw it.
Attila
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: "Marcin 'Qrczak' Kowalczyk" <qrczak@knm.org.pl>
Date: Wed, 26 Sep 2001 19:13:55 GMT Raw View
Wed, 26 Sep 2001 17:04:35 GMT, Tinct <tinct@163.com> pisze:
> void f(void);
> void g(void){ ... return f(); } //ok
>=20
> So, I tried some "void" usage and the result is: ( BCC 5 )
[...]
You are confusing the type void with the syntax of void in the
parameter list in function declarations. This syntax is kept for
compatibility with C, but in C++ it's the same as (). These functions
take no parameters (they don't take void) and they return void.
--=20
__("< Marcin Kowalczyk * qrczak@knm.org.pl http://qrczak.ids.net.pl/
\__/
^^ SYGNATURA ZAST=CAPCZA
QRCZAK
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: Francis Glassborow <francis.glassborow@ntlworld.com>
Date: Wed, 26 Sep 2001 22:52:29 GMT Raw View
In article <5450facb.0109251830.24554962@posting.google.com>, Tinct
<tinct@163.com> writes
>The Book "The C++ programing language" (7.3) says that a void function
>can use a call of a void function as the expression in return
>statement.
>void f(void);
>void g(void){ ... return f(); } //ok
Yes, that is explicitly supported by the standard
>
>So, I tried some "void" usage and the result is: ( BCC 5 )
>f(),g(),1,void("TEST"),2; // ok
>f(()); // error #1
What is that supposed to mean? It is clearly a syntax error.
>f(void); // error #2
Void is an incomplete type and so cannot be passed by value.
>f(g()); // error #3
Same reason. The latitude for return is specific and does not apply to
anything else. This was a conscious decision by the Standards
Committees.
>f( (g(),g()) ); //error #4
Also entirely correct and as intended.
>
>So, it means "void" is a very special type in c++ and the only way to
>call a f(void) is f().
There is no such thing. You cannot have a parameter of type void. It is
an incomplete type with a special exemption for return cases.
>#1~#4 might be useful in template or marco. I
>don't know. It is only a test for void usage.
We considered this and concluded that it would not be. A declaration
such as
void f(void);
contains two entirely different meaning for void.
For return it means that the function returns an incomplete type for
which there are no values (effectively it turns functions into
prototypes) and the second one is a Cism that means that the function
explicitly takes no arguments (it does not mean that it has an argument
of type void).
The exemption for return was introduced specifically because it was
useful to allow a generic form for a forwarding function so that:
anytype foo(/* parameter list */);
anytype bar(/* parameter list */){
return foo(/* argument list */);
}
Does not need to be special cased when anytype is void. As functions
cannot have parameters of type void there is no reason to extend the
special case.
Francis Glassborow
I offer my sympathy and prayers to all those who are suffering
as a result of the events of September 11 2001.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: Ron Natalie <ron@sensor.com>
Date: Wed, 26 Sep 2001 22:52:34 GMT Raw View
Tinct wrote:
>
> The Book "The C++ programing language" (7.3) says that a void function
> can use a call of a void function as the expression in return
> statement.
While you can have a return of a void expression in a void returning
function, you can't pass voids. This makes all of your examples
illegal.
>
> So, it means "void" is a very special type in c++ and the only way to
> call a f(void) is f().
That is correct. The only reason return (void) is allowed is for
template convenience. I guess nobody had any overwhelming desire
to need to pass voids in a template.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: Francis Glassborow <francis.glassborow@ntlworld.com>
Date: Thu, 27 Sep 2001 17:37:41 GMT Raw View
In article <SBEBMKAlJis7Ew23@ntlworld.com>, Francis Glassborow
<francis.glassborow@ntlworld.com> writes
>For return it means that the function returns an incomplete type for
>which there are no values (effectively it turns functions into
>prototypes) and the second one is a Cism that means that the function
>explicitly takes no arguments (it does not mean that it has an argument
>of type void).
I did not intend to write prototypes in the above (which is clear
nonsense) but was intending to write procedures (my fingers must have
had a mind of their own.
Francis Glassborow
I offer my sympathy and prayers to all those who are suffering
as a result of the events of September 11 2001.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]
Author: "Sektor van Skijlen" <sektor@spam-buffer.aldec.com>
Date: Thu, 27 Sep 2001 18:08:36 GMT Raw View
"Tinct" <tinct@163.com> wrote in message
news:5450facb.0109251830.24554962@posting.google.com...
> The Book "The C++ programing language" (7.3) says that a void function
> can use a call of a void function as the expression in return
> statement.
> void f(void);
> void g(void){ ... return f(); } file://ok
>
> So, I tried some "void" usage and the result is: ( BCC 5 )
> f(),g(),1,void("TEST"),2; // ok
> f(()); // error #1
> f(void); // error #2
> f(g()); // error #3
> f( (g(),g()) ); file://error #4
>
> So, it means "void" is a very special type in c++ and the only way to
> call a f(void) is f(). #1~#4 might be useful in template or marco. I
> don't know. It is only a test for void usage.
1. void serves for some specialities in the C++ syntax; for example
- the signification, that a function is not passed arguments (single
void only, the same as ())
- the signification, that a function may not return anything
These are examples of the `void' keyword can be used not as a type. This
syntax:
void f();
void g()
{ return f(); }
is a tail-chaining. The return tail chaining is enabled to unify the return
type.
The `void' can be also used as a type, especially you can cast any type
to void and this expression is like the `f()' above.
Beyond these, the `void' keyword means an abstraction type for each
data type. In practice it means that you can't create objects of this
type, but you can hold a pointer to any (data) object with void*.
If you are trying to treat `void' as a type, honor these rules.
--
Regards,
((
)) ektor
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.research.att.com/~austern/csc/faq.html ]