Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Void Main?

Reply
Thread Tools

Void Main?

 
 
Keith Thompson
Guest
Posts: n/a
 
      12-24-2009
Wang Yip <(E-Mail Removed)> writes:
> Hi What is the Void in parenthesis. I am familiar
> Main() {...}
> and
> Void Main() {...}
> but what is the
> Void Main(Void)
> mean. How to pass one Void argument. Do you intend Void Main(Void *)....
>
> I find C very confused........

[...]

Please don't top-post. See:
http://www.caliburn.nl/topposting.html
http://www.cpax.org.uk/prg/writings/topposting.php

C is case-sensitive. "Main" and "main" are two distinct identifiers,
as are "Void" and "void".

In a function declaration, the "(void)" syntax means that the
function has no parameters. It would have made more sense to use
"()" for this, but for historical reasons this special-case syntax
was necessary (empty parentheses already had a different meaning).

This is a very elementary question. We're here to help (well,
most of us are), but you're not going to have much luck learning
the language by asking one question at a time. I think you'll be
more successful if you use a good book. I recommend Kernighan &
Ritchie's "The C Programming Language", 2nd edition, affectionately
known as K&R2. There are also some good online tutorials (and a
whole lot of really bad ones).

See questions 18.9 and 18.10 of the comp.lang.c FAQ,
<http://www.c-faq.com/>, and follow the links. (The FAQ is an
excellent resource, but not suitable for learning the language
from scratch.)

--
Keith Thompson (The_Other_Keith) http://www.velocityreviews.com/forums/(E-Mail Removed) <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
 
 
 
Wang Yip
Guest
Posts: n/a
 
      12-24-2009
Hi yet I not understand... How to pass a Void argument.

In the code I use small letters but I find clearer to write with big
letters Void to show is C type not word. I can not afford book... pls
send a rapidshare link for "The C Programming Language" thanks......


On 24/12/2009 18:58, Keith Thompson wrote:
> Wang Yip <(E-Mail Removed)> writes:
>
>>Hi What is the Void in parenthesis. I am familiar
>>Main() {...}
>>and
>>Void Main() {...}
>>but what is the
>>Void Main(Void)
>>mean. How to pass one Void argument. Do you intend Void Main(Void *)....
>>
>>I find C very confused........

>
> [...]
>
> Please don't top-post. See:
> http://www.caliburn.nl/topposting.html
> http://www.cpax.org.uk/prg/writings/topposting.php
>
> C is case-sensitive. "Main" and "main" are two distinct identifiers,
> as are "Void" and "void".
>
> In a function declaration, the "(void)" syntax means that the
> function has no parameters. It would have made more sense to use
> "()" for this, but for historical reasons this special-case syntax
> was necessary (empty parentheses already had a different meaning).
>
> This is a very elementary question. We're here to help (well,
> most of us are), but you're not going to have much luck learning
> the language by asking one question at a time. I think you'll be
> more successful if you use a good book. I recommend Kernighan &
> Ritchie's "The C Programming Language", 2nd edition, affectionately
> known as K&R2. There are also some good online tutorials (and a
> whole lot of really bad ones).
>
> See questions 18.9 and 18.10 of the comp.lang.c FAQ,
> <http://www.c-faq.com/>, and follow the links. (The FAQ is an
> excellent resource, but not suitable for learning the language
> from scratch.)
>

 
Reply With Quote
 
 
 
 
Keith Thompson
Guest
Posts: n/a
 
      12-24-2009
Wang Yip <(E-Mail Removed)> writes:
> Hi yet I not understand... How to pass a Void argument.


There is no such thing as a void argument. As I explained, in
"int main(void)" the "(void)" is a special-case syntax that means
that the function takes no arguments.

> In the code I use small letters but I find clearer to write with big
> letters Void to show is C type not word. I can not afford book... pls
> send a rapidshare link for "The C Programming Language" thanks......

[...]

Again, please don't top-post. Your response belongs *below* any
quoted text, not above it. Please read the following links before
posting again:
http://www.caliburn.nl/topposting.html
http://www.cpax.org.uk/prg/writings/topposting.php

Capitalizing words such as "void" and "main" that are inherently
lowercase is not helpful, and will only cause confusion. If you
want to make it clear that you're referring to a C keyword or
identifier rather than an English word, find some other way to
do it; quotation marks are usually a reasonable way to do this.
In this context, though, even that probably isn't necessary; it's
clear enough from context what void and main mean.

I already cited questions 18.9 and 18.10 of the comp.lang.c FAQ,
<http://www.c-faq.com/>. If you had read them, you would have
found several online tutorials. I don't know what "rapidshare" is,
but as far as I know there are no *legitimate* copies of K&R2 other
than printed ones, and I won't help you obtain an illegitimate copy.

--
Keith Thompson (The_Other_Keith) (E-Mail Removed) <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
 
Reply With Quote
 
Wang Yip
Guest
Posts: n/a
 
      12-24-2009



On 24/12/2009 20:01, Keith Thompson wrote:
> Wang Yip <(E-Mail Removed)> writes:
>
>>Hi yet I not understand... How to pass a Void argument.

>
>
> There is no such thing as a void argument. As I explained, in
> "int main(void)" the "(void)" is a special-case syntax that means
> that the function takes no arguments.
>
>
>>In the code I use small letters but I find clearer to write with big
>>letters Void to show is C type not word. I can not afford book... pls
>>send a rapidshare link for "The C Programming Language" thanks......

>
> [...]
>
> Again, please don't top-post. Your response belongs *below* any
> quoted text, not above it. Please read the following links before
> posting again:
> http://www.caliburn.nl/topposting.html
> http://www.cpax.org.uk/prg/writings/topposting.php
>
> Capitalizing words such as "void" and "main" that are inherently
> lowercase is not helpful, and will only cause confusion. If you
> want to make it clear that you're referring to a C keyword or
> identifier rather than an English word, find some other way to
> do it; quotation marks are usually a reasonable way to do this.
> In this context, though, even that probably isn't necessary; it's
> clear enough from context what void and main mean.
>
> I already cited questions 18.9 and 18.10 of the comp.lang.c FAQ,
> <http://www.c-faq.com/>. If you had read them, you would have
> found several online tutorials. I don't know what "rapidshare" is,
> but as far as I know there are no *legitimate* copies of K&R2 other
> than printed ones, and I won't help you obtain an illegitimate copy.
> Hi Thanks to your great help.... I understand now but when I try below

program there is error.

#define V (void)x

f(void)
{
printf("calling f.........................\n");
}

main()
{
int x;
f(V);
}

I also try with int main(void)..... But then if I give a command line
parameter there is no error but I understand you say (void) is NO arguments.

Rapidshare is free download site... look for it, many good warez.



 
Reply With Quote
 
Seebs
Guest
Posts: n/a
 
      12-24-2009
On 2009-12-24, Johannes Schaub (litb) <(E-Mail Removed)> wrote:
> I was in the impression that the C99 Standard allows implementations to
> provide additional return types.


It does, so does C89.

> If an implementation supports "void", then
> behavior is not undefined. This is what i infer out of the "It shall be
> defined with return type of int ... or in some other implementation-defined
> manner."


> If, however, the implementation does not allow it, behavior is undefined. Is
> my interpretation wrong?


I don't think so. So I think that, if the documentation explicitly says
that an alternative declaration is acceptable, it's no longer undefined,
but it's reliant on implementation-defined behavior. There are other examples
of such things:

unsigned char *x;
long l = 3;
x = malloc(sizeof(int));
memcpy(x, &l, sizeof(long));

Obviously, this code is not portable, but whether or not it invokes undefined
behavior is implementation-defined. On a platform where sizeof(long) is the
same as sizeof(int), it does nothing undefined, it's merely stupid.

-s
--
Copyright 2009, all wrongs reversed. Peter Seebach / (E-Mail Removed)
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
 
Reply With Quote
 
Seebs
Guest
Posts: n/a
 
      12-24-2009
On 2009-12-24, Wang Yip <(E-Mail Removed)> wrote:
> Hi What is the Void in parenthesis.


There isn't one.

Please stop capitalizing bits of code, that is incorrect. If you are trying
to use the capitalization to call attention to a word, or separate it from
the surrounding text, try:
What is the "void" in parentheses?

(Note also that "parenthesis" is singular, and that questions usually
take question marks.)

> I find C very confused........


C isn't all that confused, but you are.

-s
p.s.: In a function declaration or definition, a parameter list consisting
only of the word "void" is an explicit assertion that the function takes
no arguments; in a definition, this is the same as an empty list, but in
a declaration, an empty list might indicate a function about whose calling
convention nothing is known.
--
Copyright 2009, all wrongs reversed. Peter Seebach / (E-Mail Removed)
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
 
Reply With Quote
 
Seebs
Guest
Posts: n/a
 
      12-24-2009
On 2009-12-24, Wang Yip <(E-Mail Removed)> wrote:
> Hi yet I not understand... How to pass a Void argument.


You don't. That's used when there's no argument.

> In the code I use small letters but I find clearer to write with big
> letters Void to show is C type not word.


Learn about quotes. (").

> I can not afford book... pls
> send a rapidshare link for "The C Programming Language" thanks......


Yeah, we'll totally help you steal stuff. Not.

If you can't afford a book, there's some online tutorials, but they aren't
of great quality. My suggestion would be to save up for a book; my
recommendation is usually Kim King's _C Programming: A Modern Approach_.
The second edition is in print last I checked, and quite good -- it is the
first C book I've ever seen that I'd actually recommend instead of K&R.

-s
--
Copyright 2009, all wrongs reversed. Peter Seebach / (E-Mail Removed)
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
 
Reply With Quote
 
Seebs
Guest
Posts: n/a
 
      12-24-2009
On 2009-12-24, Wang Yip <(E-Mail Removed)> wrote:
> Hi Thanks to your great help.... I understand now but when I try below
> program there is error.


Then you don't understand now.

> #define V (void)x


Wrong.

> f(void)
> {
> printf("calling f.........................\n");
> }


> main()
> {
> int x;
> f(V);
> }


The correct call would be:

f();

> I also try with int main(void)..... But then if I give a command line
> parameter there is no error but I understand you say (void) is NO arguments.


Right. (void) means no function arguments, it doesn't say anything about
what the calling enviroment might have done.

> Rapidshare is free download site... look for it, many good warez.


I'd like to walk you through this slowly.

You are writing to programmers. Do you know what programmers do for a
living, in general? They write programs. Many of these programs are
sold. If the program does not sell, there is no job for the programmer.
Some of us write books. If the book does not sell, there is no job for
the writer. (I'm glossing over internal-use-only code, of which there is
a fair bit, because it's a bit of a special case.)

In short, you're coming to a group of people most of whom make money selling
books or programs, and telling them that you are a big fan of downloading
things without paying the creators for them. Now, can you imagine any way
in which this could make people less likely to help you? I sure can.

-s
--
Copyright 2009, all wrongs reversed. Peter Seebach / (E-Mail Removed)
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
 
Reply With Quote
 
Kenny McCormack
Guest
Posts: n/a
 
      12-24-2009
In article <(E-Mail Removed)>,
Keith Thompson <(E-Mail Removed)> wrote:
....
>C is case-sensitive. "Main" and "main" are two distinct identifiers,
>as are "Void" and "void".


Strictly speaking, void is not an identifier. Main, main, and Void
are, though.

Isn't infinite reducibility fun?

 
Reply With Quote
 
Wang Yip
Guest
Posts: n/a
 
      12-24-2009
On 24/12/2009 20:33, Seebs wrote:
> On 2009-12-24, Wang Yip <(E-Mail Removed)> wrote:
>
>>Hi Thanks to your great help.... I understand now but when I try below
>>program there is error.

>
>
> Then you don't understand now.
>
>
>>#define V (void)x

>
>
> Wrong.
>
>
>>f(void)
>>{
>>printf("calling f.........................\n");
>>}

>
>
>>main()
>>{
>>int x;
>>f(V);
>>}

>
>
> The correct call would be:
>
> f();
>
>
>>I also try with int main(void)..... But then if I give a command line
>>parameter there is no error but I understand you say (void) is NO arguments.

>
>
> Right. (void) means no function arguments, it doesn't say anything about
> what the calling enviroment might have done.
>
>
>>Rapidshare is free download site... look for it, many good warez.

>
>
> I'd like to walk you through this slowly.
>
> You are writing to programmers. Do you know what programmers do for a
> living, in general? They write programs. Many of these programs are
> sold. If the program does not sell, there is no job for the programmer.
> Some of us write books. If the book does not sell, there is no job for
> the writer. (I'm glossing over internal-use-only code, of which there is
> a fair bit, because it's a bit of a special case.)
>
> In short, you're coming to a group of people most of whom make money selling
> books or programs, and telling them that you are a big fan of downloading
> things without paying the creators for them. Now, can you imagine any way
> in which this could make people less likely to help you? I sure can.
>
> -s For call f(); I will just write

f(){...}
not
f(void){...}

What is difference with void. Both no arguments.

What is calling environment???? Is not what I learn.

Writers of book are very rich.. I am very poor.. I think they are happy
to share books to developing countries......
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the difference between void proba(); and void proba(void); ??? PencoOdStip@gmail.com C++ 1 05-23-2007 07:12 PM
what is the difference, void func(void) and void fucn() noblesantosh@yahoo.com C Programming 5 07-22-2005 04:38 PM
"void Method()" vs "void Method(void)" Ollej Reemt C++ 7 04-22-2005 03:47 AM
returning a void (*)(void) Sergio C++ 6 01-05-2005 08:30 PM
`void **' revisited: void *pop(void **root) Stig Brautaset C Programming 15 10-28-2003 09:03 AM



Advertisments