C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Using a typedef to void for an empty parameter list produces

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
Philipp Reh
Guest





PostPosted: Sun May 20, 2007 11:48 pm    Post subject: Using a typedef to void for an empty parameter list produces Reply with quote



Dear group,

I recently tried gcc-4.2 with some of my code. When compiling something
that includes headers of 'devil' it complains about the following
(narrowed down) case:

typedef void ILvoid;

ILvoid f(ILvoid);

int main()
{
}

It even fails with no arguments to g++ at all: "g++ -c myfile.cpp".
The error message is:

"error: '<anonymous>' has incomplete type"
"error: invalid use of 'ILvoid'"

for in the line delcaring f.

So why should this be illegal? It just happens for the parameter type
(not for the return type). Is gcc right or wrong here?

Cheers,
Philipp Reh


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Alberto Ganesh Barbati
Guest





PostPosted: Mon May 21, 2007 4:56 am    Post subject: Re: Using a typedef to void for an empty parameter list prod Reply with quote



Philipp Reh ha scritto:
Quote:

typedef void ILvoid;

ILvoid f(ILvoid);

int main()
{
}

It even fails with no arguments to g++ at all: "g++ -c myfile.cpp".
The error message is:

"error: '<anonymous>' has incomplete type"
"error: invalid use of 'ILvoid'"

for in the line delcaring f.

So why should this be illegal? It just happens for the parameter type
(not for the return type). Is gcc right or wrong here?

I would say that the code is ill-formed and gcc is correct. The standard
says in 8.3.5/2 that "The parameter list (void) is equivalent to the
empty parameter list." Even if T is a typedef for void, (T), as a
sequence of tokens, is not the same as (void), therefore the special
case doesn't apply.

HTH,

Ganesh

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Mathias Gaunard
Guest





PostPosted: Mon May 21, 2007 4:58 am    Post subject: Re: Using a typedef to void for an empty parameter list pro Reply with quote



On May 21, 1:48 am, Philipp Reh <s...@s-e-f-i.de> wrote:

Quote:
typedef void ILvoid;

ILvoid f(ILvoid);

int main()
{

}

It even fails with no arguments to g++ at all: "g++ -c myfile.cpp".

[...]

So why should this be illegal? It just happens for the parameter type
(not for the return type). Is gcc right or wrong here?

I don't know whether it's right or wrong, but I wouldn't really expect
this to work.

T foo(void) is really something specific. It doesn't mean that the
function takes a first argument of type void, it means it takes no
argument.

By the way, that feature is deprecated and only available for C
compatibility. You'd better write T foo()


--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Alberto Ganesh Barbati
Guest





PostPosted: Mon May 21, 2007 11:20 am    Post subject: Re: Using a typedef to void for an empty parameter list pro Reply with quote

Mathias Gaunard ha scritto:
Quote:

T foo(void) is really something specific. It doesn't mean that the
function takes a first argument of type void, it means it takes no
argument.

By the way, that feature is deprecated and only available for C
compatibility. You'd better write T foo()


It's true that C++ programmers are encouraged to avoid this feature,
but, strictly speaking, it has not yet been formally deprecated. The
list of formally deprecated features is in annex D of the standard.

Ganesh

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
 


Powered by phpBB © 2001, 2006 phpBB Group