"int fegetround(void);"

Discussion in 'C++' started by Stefan Ram, Jan 10, 2013.

  1. Stefan Ram

    Stefan Ram Guest

    n3290 contains the synopsis

    int fegetround(void);

    in 26.3.1. Why have they kept the »void« from C instead of

    int fegetround();

    , which has the same meaning in C++ IIRC, but is shorter?
    Stefan Ram, Jan 10, 2013
    #1
    1. Advertising

  2. On 1/10/2013 2:09 AM, Stefan Ram wrote:
    > n3290 contains the synopsis
    >
    > int fegetround(void);
    >
    > in 26.3.1. Why have they kept the »void« from C instead of
    >
    > int fegetround();
    >
    > , which has the same meaning in C++ IIRC, but is shorter?


    Probably so that the declaration could be shared between C headers and
    C++ headers *verbatim*. Also, not to confuse any readers who are
    accustomed to seeing '(void)' due to their extended exposure to C... As
    you say, it does have the same meaning. Shortening by four symbols is
    not critical for adding clarity or speeding up compilation, IMHO.

    V
    --
    I do not respond to top-posted replies, please don't ask
    Victor Bazarov, Jan 10, 2013
    #2
    1. Advertising

  3. Stefan Ram

    Öö Tiib Guest

    On Thursday, 10 January 2013 09:09:07 UTC+2, Stefan Ram wrote:
    > n3290 contains the synopsis
    >
    > int fegetround(void);
    >
    > in 26.3.1. Why have they kept the »void« from C instead of
    >
    > int fegetround();


    For compatibility with C. Number of C developers use C++ compiler to
    compile C code. They do it for stricter casting rules. For that to work
    they have to use the syntax that means same in both languages.
    Also for backward compatibility. It has been so for decades so there
    is plenty of C++ code that has such redundant voids and it has to compile.

    > , which has the same meaning in C++ IIRC, but is shorter?


    Yes, if it is C++ code then that void is redundant. Especially pointless
    it is for member functions or default constructors or destructors that
    can not be available in C anyway. If it annoys you then write into your
    coding standard that usage of redundant void parameters in C++ function
    or member function declarations or definitions are forbidden in your code.
    Öö Tiib, Jan 10, 2013
    #3
  4. Stefan Ram

    Greg Martin Guest

    On 13-01-10 05:41 AM, Victor Bazarov wrote:
    > On 1/10/2013 2:09 AM, Stefan Ram wrote:
    >> n3290 contains the synopsis
    >>
    >> int fegetround(void);
    >>
    >> in 26.3.1. Why have they kept the »void« from C instead of
    >>
    >> int fegetround();
    >>
    >> , which has the same meaning in C++ IIRC, but is shorter?

    >
    > Probably so that the declaration could be shared between C headers and
    > C++ headers *verbatim*. Also, not to confuse any readers who are
    > accustomed to seeing '(void)' due to their extended exposure to C... As
    > you say, it does have the same meaning. Shortening by four symbols is
    > not critical for adding clarity or speeding up compilation, IMHO.
    >
    > V


    Either declaration is valid C as well but they have different meanings.
    The first specifies no parameters and the second means unspecified
    parameters. You might use the second if you wished to have different
    argument lists used under different compilation circumstances or,
    sometimes, for a function pointer declaration that served different
    purposes. If you've used GTK+ you'e seen that idiom.

    If you intend to compile your program as either C or C++ and wanted the
    compiler to be able to check parameters you would use the first form.
    Greg Martin, Jan 10, 2013
    #4
    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.

Share This Page