472,126 Members | 1,560 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,126 software developers and data experts.

meaning of "empty pair" of parenthesis ?

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

Mar 14 '07 #1
10 6739
arnuld wrote:
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.

--
Chris "electric hedgehog" Dollin
The shortcuts are all full of people using them.

Mar 14 '07 #2
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?

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Mar 14 '07 #3

"arnuld" <ge*********@gmail.comwrote in message
news:11********************@l75g2000hse.googlegrou ps.com...
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

--
Stephen Sprunk "Those people who think they know everything
CCIE #3723 are a great annoyance to those of us who do."
K5SSS --Isaac Asimov
--
Posted via a free Usenet account from http://www.teranews.com

Mar 14 '07 #4
In article <45***********************@free.teranews.com>,
Stephen Sprunk <st*****@sprunk.orgwrote:
>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?
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
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Mar 14 '07 #5
Richard Tobin wrote:

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

Mar 14 '07 #6
In article <11**********************@l75g2000hse.googlegroups .com>,
santosh <sa*********@gmail.comwrote:
>Richard Tobin wrote:

<snip>
>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.
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")

Mar 14 '07 #7
On 14 Mar 2007 05:24:21 -0700, in comp.lang.c , "arnuld"
<ge*********@gmail.comwrote:
>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
Mar 14 '07 #8
"santosh" <santosh....@gmail.comwrote:
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.
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.

--
Peter

Mar 14 '07 #9
On Mar 15, 9:47 am, gaze...@xmission.xmission.com (Kenny McCormack)
wrote:
santosh <santosh....@gmail.comwrote:
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.
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).

Mar 15 '07 #10
In article <11*********************@o5g2000hsb.googlegroups.c om>,
Old Wolf <ol*****@inspire.net.nzwrote:
>On Mar 15, 9:47 am, gaze...@xmission.xmission.com (Kenny McCormack)
wrote:
>santosh <santosh....@gmail.comwrote:
>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.

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!

Mar 15 '07 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Valery | last post: by
4 posts views Thread by Marcin Dobrucki | last post: by
10 posts views Thread by mcbobin | last post: by
1 post views Thread by newbie | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.