typedef void question

Discussion in 'C++' started by Schüle Daniel, Feb 2, 2008.

  1. Hi,

    $ cat main.cpp
    #include <iostream>

    //#define VOID void
    typedef void VOID;

    VOID foo() {
    std::cout << "in foo" << std::endl;
    }

    void bar(VOID) {
    std::cout << "in bar" << std::endl;
    }

    int main() {
    foo();
    bar();
    return 0;
    }

    I am using g++ 4.2.2 and 3.4.6

    the interesting thing is that g++4.2.* doesn't like
    bar prototype. compiling it yields

    main.cpp:10: error: ‘<anonymous>’ has incomplete type
    main.cpp:10: error: invalid use of ‘VOID’
    main.cpp: In function ‘int main()’:
    main.cpp:10: error: too few arguments to function ‘void bar(<type error>)’
    main.cpp:16: error: at this point in file

    g++3.4.6 hat no problems with bar

    and both compile foo without problems

    what was wrong with the above defintion of bar
    that g++ changed its behaviour?

    Regards, Daniel

    ps: using #define VOID void works of course with all compilers
     
    Schüle Daniel, Feb 2, 2008
    #1
    1. Advertising

  2. Schüle Daniel wrote:
    > ...
    > what was wrong with the above defintion of bar
    > that g++ changed its behaviour?
    > ...


    Must be some glitch in gcc. Using a typedef-name for 'void' to declare an empty
    parameter list is not allowed in C++. The wording in 8.3.5/2 is intended to mean
    that it should be specifically spelled as '(void)' in order to make a valid
    parameter declaration list.

    There was an early defect report about this - #18

    http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_closed.html#18

    It's status is NAD - "not a defect", meaning that the standard was clear on that
    from the very beginning.

    --
    Best regards,
    Andrey Tarasevich
     
    Andrey Tarasevich, Feb 2, 2008
    #2
    1. Advertising

  3. [...]
    >
    > Must be some glitch in gcc. Using a typedef-name for 'void' to declare
    > an empty parameter list is not allowed in C++. The wording in 8.3.5/2 is
    > intended to mean that it should be specifically spelled as '(void)' in
    > order to make a valid parameter declaration list.
    >


    so it's an improvement in g++ standard compliance

    I discovered this using opengl related code
    /mesa/include/GL:[12]$ cat gl.h | awk '/^typedef.*void.*GLvoid;$/'
    typedef void GLvoid;

    hmm, there is no sense to typedef void

    thx
     
    Schüle Daniel, Feb 3, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ollej Reemt
    Replies:
    7
    Views:
    602
    Jack Klein
    Apr 22, 2005
  2. Stig Brautaset

    `void **' revisited: void *pop(void **root)

    Stig Brautaset, Oct 25, 2003, in forum: C Programming
    Replies:
    15
    Views:
    836
    The Real OS/2 Guy
    Oct 28, 2003
  3. Replies:
    5
    Views:
    881
    S.Tobias
    Jul 22, 2005
  4. Replies:
    1
    Views:
    435
    Victor Bazarov
    May 23, 2007
  5. jack
    Replies:
    2
    Views:
    1,344
    Thomas Maier-Komor
    Nov 27, 2009
Loading...

Share This Page