"int fegetround(void);"

S

Stefan Ram

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?
 
V

Victor Bazarov

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
 
Ö

Öö Tiib

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.
 
G

Greg Martin

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top