meaning of "empty pair" of parenthesis ?

C

Chris Dollin

arnuld said:
this is from Steve Summit C notes:

The empty pair of parentheses indicates that our main function accepts
no arguments, that is, there isn't any information which needs to be
passed in when the function is called. [1]

i think, an "empty pair" of parenthesis means a function can take
unlimited number of arguments

Not in a C definition it doesn't. Nor in a declaration.
 
A

arnuld

this is from Steve Summit C notes:

The empty pair of parentheses indicates that our main function accepts
no arguments, that is, there isn't any information which needs to be
passed in when the function is called. [1]

i think, an "empty pair" of parenthesis means a function can take
unlimited number of arguments



[1] http://www.eskimo.com/~scs/cclass/notes/sx1a.html
 
R

Richard Heathfield

arnuld said:
this is from Steve Summit C notes:

The empty pair of parentheses indicates that our main function accepts
no arguments, that is, there isn't any information which needs to be
passed in when the function is called. [1]

Steve is correct. (More precisely, our main function accepts no
parameters. But it's a fine point.)
i think, an "empty pair" of parenthesis means a function can take
unlimited number of arguments

But Steve just explained what it means! What grounds do you have for
believing that Steve is wrong?
 
S

Stephen Sprunk

arnuld said:
this is from Steve Summit C notes:

The empty pair of parentheses indicates that our main function
accepts no arguments, that is, there isn't any information which
needs to be passed in when the function is called. [1]

i think, an "empty pair" of parenthesis means a function can take
unlimited number of arguments

Consider:

void foo();
void bar(void);
void baz() {}

foo is a function that takes an unspecified number of arguments. bar and
baz are both functions that take zero arguments. See the differences?

(This doesn't make perfect sense because it's a historical artifact of C.
C++ is much saner; if you learned the C++ rules thinking they were C rules,
you'll be very confused. C++ is not C.)

S
 
R

Richard Tobin

i think, an "empty pair" of parenthesis means a function can take
unlimited number of arguments
[/QUOTE]
Consider:

void foo();
void bar(void);
void baz() {}

foo is a function that takes an unspecified number of arguments. bar and
baz are both functions that take zero arguments. See the differences?

To be explicit: in pre-ANSI C, function declarations specified only
the return type, not the arguments, and definitions specified the
arguments with a syntax like this:

int main(argc, argv)
int argc;
char **argv;
{
...

So if you see

int foo();

this is an old-style declaration of foo which does not specify the
arguments. It doesn't mean it has an unlimited number, it just doesn't
say anything about it.

The modern way to write it is:

int foo(void);

if it doesn't take any arguments, or (for example):

int foo(int a, double b);

if it takes an int and a double argument.

In modern C, the function definition looks the same as the declaration:

int foo(void)
{
...

but in old-style it would look like:

int foo()
{
...

so the interpretation of the empty parameter list was quite different in
declarations and definitions: in declarations it meant nothing, but in
definitions it meant that there were no arguments. The modern syntax is
more consistent, if not elegant.

Furthermore, it was (and still is in C90) legal to omit the return type
if it's int. So the original example:

main()
{
...

specifies main() as taking no arguments and returning an int.

-- Richard
 
S

santosh

Richard Tobin wrote:

Furthermore, it was (and still is in C90) legal to omit the return type
if it's int. So the original example:

main()
{
...

specifies main() as taking no arguments and returning an int.

Info for "arnuld":

The C99 Standard has removed implicit int.

If a function doesn't return any value, it must be declared as
returning void.
 
K

Kenny McCormack

Richard Tobin wrote:



Info for "arnuld":

The C99 Standard has removed implicit int.

So? There's no foul here. Poster claimed that both before and after
the C90 spec was published, implicit int was legal. And he is right.
If a function doesn't return any value, it must be declared as
returning void.

Only if you are using C99 or some other environment that requires it
(such as "gcc -Wall")
 
M

Mark McIntyre

this is from Steve Summit C notes:

The empty pair of parentheses indicates that our main function accepts
no arguments, that is, there isn't any information which needs to be
passed in when the function is called. [1]

in a definition, this is correct.
i think, an "empty pair" of parenthesis means a function can take
unlimited number of arguments

No.
In a declaration it would mean the function took an unspecified number
of arguments, and the function definition would have to say precisely
how many.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
 
P

Peter Nilsson

santosh said:
Info for "arnuld":

The C99 Standard has removed implicit int.
True.

If a function doesn't return any value, it must be declared as
returning void.

Not strictly true. C99 continues to support non-void functions
that don't return a value, so long as the calling function doesn't
attempt to use a return value from the function.

But note that main should not be declared as a void function
in portable code.
 
O

Old Wolf

So? There's no foul here. Poster claimed that both before and after
the C90 spec was published, implicit int was legal. And he is right.

There's nothing wrong with providing additional information
beyond a literal answer of the OP's question (as you are so
often wont to point out).
 
K

Kenny McCormack

There's nothing wrong with providing additional information
beyond a literal answer of the OP's question (as you are so
often wont to point out).

When in Rome, do like a Roman!
 

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