Velocity Reviews - Computer Hardware Reviews

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

Reply
Thread Tools

Void Main?

 
 
Wang Yip
Guest
Posts: n/a
 
      12-24-2009



On 24/12/2009 16:50, Kaz Kylheku wrote:
> On 2009-12-24, Wang Yip <(E-Mail Removed)> wrote:
>
>>Hello I read Main shall not return Void but I always use and always
>>work.... who is right

>
>
> Of what value is your ``always''?
>
> How different are your uses from each other?
>
> If you use ``viod main'' in five hundred different programs, and it
> always works, but they all use the same compiler, run-time library
> and operating system, don't you think that these 500 programs
> are really just one test case? Don't you think that these 500 programs
> demonstrate only a /single/ data point: that void main works with
> that compiler and run-time environment?
>
> It's a big jump from a single data point to ``always''.
>
> Consider this: C has a static type system. Functions have a type.
> The function int X(int) is not compatible with void Y(int) .
>
> If you were writing a device driver at an embedded company, and one
> of the functions is declared as a pointer:
>
> int (*transmit)(netdev *dev, netpacket *);
>
> would you implement it like this:
>
> void my_transmit(netdev *dev, netpacket *);
>
> ?
>
> Your compiler would tell you that the address of my_transmit
> is not assignment-compatible to the transmit function pointer:
>
> static netdev dev = { ..., my_transmit, ...}; /* error */
>
> Suppose it's only a warning, and it compiles anyway. When the OS calls
> the driver's my_transmit, what do you think happens when the function
> returns? The caller expects a return value, but the function is void.
>
> Can you point the newsgroup to the chapter of some document
> which defines what happens in that situation?
>
> What makes you think you can just pick a random function type out of the
> air and use that for your main function?

We hear "C programmers must manage memory for themselves". Is mean I
must know when to write to virtual swap page in disk and how to do it....
 
Reply With Quote
 
 
 
 
Keith Thompson
Guest
Posts: n/a
 
      12-24-2009
Wang Yip <(E-Mail Removed)> writes:
[...]
>> -s For call f(); I will just write

> f(){...}
> not
> f(void){...}
>
> What is difference with void. Both no arguments.


You're wrong. This:

void f(void) { /* ... */ }

says that f takes no arguments. This:

void f() { /* ... */ }

says that f expects a fixed but unspecified number and type(s)
of arguments. If you incorrectly call f with an argument, such as
f(42) or f("Hello"), the compiler probably qwon't diagnose the error.

This is a feature that exists only for historical reasons; it's not
something you need to worry about. Just don't use empty parentheses
in a function definition or declaration. (You do need to use empty
parentheses in a function call if you're not passing any arguments.)

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


Seebs was referring to the way your program is invoked.

If you write:

int main(void) { /* ... */ }

any command-line arguments you specify when you run your program will
be quietly ignored.

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


Stealing is ok if you're poor?

We will not help you obtain stolen copies of books. If you continue
to ask about it, we will not help you with anything else either.
There are free tutorials on the web.

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



On 24/12/2009 21:31, Keith Thompson wrote:
> Wang Yip <(E-Mail Removed)> writes:
> [...]
>
>>>-s For call f(); I will just write

>>
>>f(){...}
>>not
>>f(void){...}
>>
>>What is difference with void. Both no arguments.

>
>
> You're wrong. This:
>
> void f(void) { /* ... */ }
>
> says that f takes no arguments. This:
>
> void f() { /* ... */ }
>
> says that f expects a fixed but unspecified number and type(s)
> of arguments. If you incorrectly call f with an argument, such as
> f(42) or f("Hello"), the compiler probably qwon't diagnose the error.
>
> This is a feature that exists only for historical reasons; it's not
> something you need to worry about. Just don't use empty parentheses
> in a function definition or declaration. (You do need to use empty
> parentheses in a function call if you're not passing any arguments.)
>
>
>>What is calling environment???? Is not what I learn.

>
>
> Seebs was referring to the way your program is invoked.
>
> If you write:
>
> int main(void) { /* ... */ }
>
> any command-line arguments you specify when you run your program will
> be quietly ignored.
>
>
>>Writers of book are very rich.. I am very poor.. I think they are
>>happy to share books to developing countries......

>
>
> Stealing is ok if you're poor?
>
> We will not help you obtain stolen copies of books. If you continue
> to ask about it, we will not help you with anything else either.
> There are free tutorials on the web.
> So this is bug.. no error message when arguments passed to (void) Main

function. Must not be quietly ignore.

Is no stealing.. only copyright. US copyright law have no force here.....
 
Reply With Quote
 
Peter Nilsson
Guest
Posts: n/a
 
      12-24-2009
On Dec 25, 8:44*am, Wang Yip <(E-Mail Removed)> wrote:
> Is no stealing.. only copyright. US copyright law have no force
> here.....


I'm not sure where your 'here' is, but I'll take a stab...

<http://en.wikipedia.org/wiki/
Intellectual_property_in_the_People's_Republic_of_ China>

--
Peter
 
Reply With Quote
 
Seebs
Guest
Posts: n/a
 
      12-24-2009
On 2009-12-24, Wang Yip <(E-Mail Removed)> wrote:
> For call f(); I will just write
> f(){...}
> not
> f(void){...}


> What is difference with void. Both no arguments.


I already explained this. Your not choosing to read it is not my problem.

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


The caller of a function is the thing which calls it. When you invoke
a program, though, "main" is called by something outside your code -- I
was referring to this as "the calling environment".

> Writers of book are very rich..


Utterly untrue. Writing, for the vast majority of people, pays substantially
less than the cost of living. If I'd put as many hours working in the
lowest-paying retail job that exists as I put into my book, it would have paid
about 2x as much.

> I am very poor.. I think they are happy
> to share books to developing countries......


Some might be, but they are not in general big fans of people who habitually
steal everything.

It might make more sense to, instead of declaring that other people have
whatever beliefs or feelings would be convenient to you, to listen to them
when they tell you what they believe or feel.

Your problem isn't that you're poor; it's that you don't listen carefully
or think about things. You have the same attitude towards learning
programming that you have towards the book; you're expecting people to
hand you everything all at once for free, and not putting in even the most
basic effort.

Show some willingness to put in effort, think about things, and ask
reasonable questions, and you'll get a lot more responses. Keep on like
this and a lot of people will just ignore your questions.

-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:
> Is no stealing.. only copyright. US copyright law have no force here.....


Who cares about laws?

The question is not what is legal; it is what is respectful to other
people. You're not.

-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
 
Flash Gordon
Guest
Posts: n/a
 
      12-24-2009
Wang Yip wrote:

<snip>

> Is no stealing.. only copyright. US copyright law have no force here.....


If you are in a country which ignores international copyright, then we
have even *more* reason to not provide you with any copyright material.

For a lot of people here either there sole income, or the majority of
their income, is derived from the sale of copyright material. By
obtaining copyright material without paying for it you are depriving
people of their income. People like those you want to help you.

If you cannot afford to pay people for their work, look at the resources
people chose to provide for free. Keith has already told you where to
find some.
--
Flash Gordon
 
Reply With Quote
 
Beej Jorgensen
Guest
Posts: n/a
 
      12-24-2009
On 12/24/2009 01:04 PM, Wang Yip wrote:
> Writers of book are very rich..


Ha! Where in the world is this that authors are very rich? I would
like to live there.

I honestly don't care if you personally pirate books or not--you weren't
going to buy them anyway, so you don't represent lost revenue, is the
way I look at it. Hell, you can make as many copies of each book as you
want--aren't I the generous one.

But people busted their asses to get those books written; you should
acknowledge that you're taking something (the book, the knowledge
within, the results of the author's labors, or whatever) without giving
anything in return.

Remember this, because someday you should also give back to the world to
balance what you have taken.

-Beej

 
Reply With Quote
 
Keith Thompson
Guest
Posts: n/a
 
      12-24-2009
Wang Yip <(E-Mail Removed)> writes:
[...]
> Is no stealing.. only copyright. US copyright law have no force here.....


Then you'll get no more help from me.

--
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
 
Keith Thompson
Guest
Posts: n/a
 
      12-25-2009
"BGB / cr88192" <(E-Mail Removed)> writes:
[...]
> keep in mind that many OS's, including Linux and Windows, actually use this
> error code for something:
> to know whether the program exited properly, or experienced some internal
> error state, and in which case, the return value gives an error code (which
> itself depends on OS).
>
> typically, return values are:
> 0, success / no error;
> -1, failed / generic error.
>
> values >0 are, typically, successful codes which give some sort of
> context-dependent meaning (or may also be error codes, depending on
> specifics).


On Unix and Unix-like systems, an exit status of 0 denotes success,
and *positive* values denote errors (1 is usually a generic error
indication). Negative values are not actually possible; if a C
program executes "exit(-1)", the invoking program sees a status
of 255.

You may be thinking of conventions for results returned by library
functions rather than a program's exit status.

I think Windows is similar, but I don't do much Windows programming
so I could be mistaken.

OpenVMS (formerly VMS) uses even numbers for failure, odd numbers for
success.

This is why the C standard defines EXIT_SUCCESS and EXIT_FAILURE.

[...]
> so, the general rule is, don't have main return void, then it may just
> return garbage in a place where a meaningful value is expected (even if not
> always acted on).


That's one likely consequence, but the behavior is actually undefined.
The compiler is free to reject your program, or to generate code that
corrupts the stack.

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