Void Main?

W

Wang Yip

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

Keith Thompson

Wang Yip said:
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.
 
W

Wang Yip

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




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.




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

Seebs

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
 
S

Seebs

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
 
F

Flash Gordon

Wang Yip wrote:

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

Beej Jorgensen

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
 
K

Keith Thompson

BGB / cr88192 said:
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.
 
W

Wang Yip

Then you'll get no more help from me.
Hi Look is different law here.. USA have stupid copyright law, not all of
world is US empire yet US want impose bad law on everyone. Please respect
the law to other countries, we are independent country see.....

Also if you hire in Nokia I am eager to get it. Expert C programmer..
lots of experience.. many work in cell phone area.. excellent English
written and spoken. Please email to complete CV.
 
F

Flash Gordon

Wang said:
Hi Look is different law here.. USA have stupid copyright law, not all of
world is US empire yet US want impose bad law on everyone. Please respect
the law to other countries, we are independent country see.....

It's international copyright law, not simply US copyright law.
Also if you hire in Nokia I am eager to get it. Expert C programmer..

Expert but you don't know about void in parameter lists? Hardly.
lots of experience..

I doubt it.
many work in cell phone area.. excellent English
written and spoken.

Your written English is *not* excellent, and your comprehension is not
that good as evidenced by your lack of understanding shown in this group.
Please email to complete CV.

Do you seriously think that people would want you working on their
software when you would not expect their intellectual property rights?
Based on your postings here I would expect you to take the money for
developing software then go and sell or give it to the competition.
 
E

Eric Sosman

world is US empire yet US want impose bad law on everyone. Please respect
the law to other countries, we are independent country see.....

Also if you hire in Nokia I am eager to get it. Expert C programmer..

On the evidence available, this is an absurd overestimate
of your abilities.
lots of experience.. many work in cell phone area.. excellent English
written and spoken.

On the evidence available, this is an absurd overestimate
of your abilities.
Please email to complete CV.

No, thanks. I'm not interested in hiring anyone who thinks
"Whatever I can't be prosecuted for" is "Right."
 
B

BGB / cr88192

Keith Thompson said:
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.

oh, ok.
was not aware of this...

I usually just returned 0 from main anyways, unless there were good reason
to do otherwise (typically error status from certain command line tools).

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.

ok.

I have observed (mostly in the debuggers), apps returning with (or what look
like) SEH exception codes (usually if something goes wrong internally, and
it is an error not of the sort caught by the debugger).

so, occasional exit codes like 0x80f00ba5 / ...

[...]
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.

although, most typically it is just garbage, or at least on x86 and friends.

this is because compilers tend to generate something like:
"mov esp, ebp
pop ebp
ret"

or:
"mov rsp, rbp
pop rbp
ret"

or:
"add rsp, 48
pop ...
ret"

or:
"lea rsp, [r12+32]
pop ...
ret"

or: ...


it would be trivial for a compiler to add an extra "xor rax, rax" in the
mix, but I have not seen any which do so (since this is a needless waste of
clock cycles...).
 
B

BGB / cr88192

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


Learn about quotes. (").


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.

note that in some countries, such as the PRC, this would not be stealing as
such...
hence one can buy things like Windows / ... for not much more than the cost
of the disk (such as getting it for maybe 10 yuan or so, or ~1.20$).

there, it is not actually illegal as such.

however, if you take a physical object (such as running of with the actual
disk, or with a printed book), then matters are a bit more grim.

(and, if you want to recover the costs, little stops one from running off a
few copies and selling them as well...).


for example, for anyone living in Asia, the PRC is generally somewhere to go
to get cheap prices, although in the US the plane trip would more than make
up for any potential savings (as well as being terribly inconvinient, as
going from Asia to the US ended up with around 24 hours solid of being on
planes...). (as well as many pieces of such merchandise having import/export
restrictions, ...).


but, anyways, it is worth noting that there are differences in perspective,
and not everyone holds the same values WRT these matters.
 
B

BGB / cr88192

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

it is only 24 hours of plane rides and getting a visa away...

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.

well, it is worth noting that, in that part of the world, ideals and values
are a bit different than in more westernized countries.

it can be noted that in many respects, the westernized ideals are far from
ideal (one can see at the same time a world of progress, and a world of
depravity and degeneracy...). yet, in the western world, it is common
practice to ignore ones' failings and ones' depreaved behavior, and at the
same time take a high stand over particular ideas that they themselves have
created.

for example, it is glorified to have a lewd and promiscuous lifestyle, and
yet condemn others for not paying them for every word they speak or write
down... it is almost as if people expect an entitlement for their own
vanity.

(and, yes, no fair maiden is safe when there are Americans around...).


I say this while still being an American, as such...

the point here though is not simply to assume that everywhere, everything is
seen in quite the same way.
 
B

BGB / cr88192

Seebs said:
Who cares about laws?

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

and, one can ask, are you certain there is a difference?...

it depends on ones' exact views, but ethics and respect are laws, although
not necessarily national ones.


for example, one could assert that, what is right or wrong is primarily a
matter of the applicable laws, and so if a law says something is legal, then
it is the right thing to do, and if it is not legal, it is not the right
thing to do.

since, after all, the governments (typically) make laws regarding the public
good.


granted, personally, I believe in a higher set of laws, but it just so
happens that one of these laws is to respect laws set in place by rulers.

however, this has an interesting side effect:
since laws differ from place to place, and from context to context, what is
right or wrong is given some level of regional variation.

so, what is the "right thing to do" is different between, say, the PRC and
the US, or at least WRT "the laws of men".
however, this does not extend to things which are specified as right or
wrong in contrast to national laws.

for example, lewd and promiscuous behavior (such as, for example, people
becoming "intimate" without first having been married, ...) is still
immoral, even though, for example, the US does not have laws against it
(actually, there are some US laws which still classify it as immoral as
such, but none by which one would be prosecuted).


similarly, in some contexts one may be under additional obligations not
otherwise mandated either at the national or religious level.

for example, if a person enters a synogogue, they may be expected to follow
the usual laws applicable there (for example, respecting kosher, having a
kippah if present during services, ...) even though, elsewhere one may be
under no obligation to follow these rules (for example, because the NT no
longer mandates it, or because it is a personal act of piety rather than a
moral sanction, ...).

by being present there, one is morally bound, even if otherwise these would
no longer be binding.

similarly, one could debate whether being of a given ethnicity would make
these rules binding, but then take note that one is not bound because, for
example, they don't have maternal descent (given paternal descent is not
binding as such, ...).


similarly, elsewhere (such as around Asians) it may be required that one bow
as a matter of respect, ... and this much is binding, but elsewhere it would
be inappropriate to bow to people, ...


(although, within limits, one is not bound to follow rules in conflict with
greater rules).

granted, there are other possible interpretations of moral ethics, but most
of them (in my case at least) tend to differ more at the meta-ethical level,
rather than in terms of the overall conclusions.
 
S

spinoza1111

Who cares about laws?

I do. Especially about defamation, punk. And Wang Yip is wrong: China
is a signatory to international laws which form part of its domestic
law, and US copyright is supposed to be respected in China.
Furthermore, if the best the US can come up with is C, China could do
better. Russian trade unionists visited the computer center in which I
worked to steal our technology because they were damned if they'd let
their own programmers actually think originally.
The question is not what is legal; it is what is respectful to other
people.  You're not.

Is calling a fellow Apress author a moron respectful? Is deleting his
email attempts to resolve differences respectful? Is enabling thugs
like Argonaut respectful? And is posting twenty trite criticisms of a
prolific and hard-working computer author respectful?
 
S

spinoza1111

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


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

....which occupies a mythical, theological position in the minds of
worshipers of the machine such that it's become a shibboleth to return
to the host in a certain approved way, although in practice it matters
jack shit. The important thing, esp. if you're in fact without formal
education in comp sci and your job is merely labeled "programmer", is
showing you're a member of the one true religion.
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.

You don't seem to be aware of the conditions abroad. In China, I was
paid at the level of a middle manager, and this is only 30K per year.
But I minded not at all since costs were correspondingly lower EXCEPT
for the costs of, guess what, American computer books and closed
source software, which were out of scale to technical salaries and
company budgets.

Had I been able to legally stay after leaving the firm, I could have
survived on Apress royalties and part time work. A guy like your pal
Schildt would live like a king since his books are so popular despite
your campaign.

As in the case of "C: The Complete Nonsense" you just don't do your
homework.

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

The Chinese don't steal "everything". At the company I worked, the
developers had legally reverse-engineered the complete syntax of
Visual Basic by working days and night in record time whereas in
America the developers would have pleaded that they had a fashionable
disease and needed to go home to Mommy.

The fact is that Microsoft hasn't figured out how to fairly price
Enterprise platform software for the international market, for if it
did so, people would buy it in Asia. The result was that my company
used open source. This was prior to the release of Express versions of
Microsoft software.

Certain books are for sale in "international" editions in Xin Hua
bookstore in downtown Shenzen and Commercial Press in Hong Kong, but
they are textbooks on academic subjects such as algorithms.
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.

Kinda like a guy who doesn't want to take academic classes in comp
sci.
 
S

spinoza1111

[...]
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 address 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"

....and so it begins...the second-hand bullying of Wang Yip by people
who take their cue from others, have never worked in China, have no
compassion, and like to show off...

Mr Wang (do I have the surname correct?) the Internet in America is
like the Cultural Revolution in China, because it empowers bullies to
take their cue from others, and pursue safe targets. While you need to
obey American corporate law, I understand your difficulties as a
developer in China, since I worked as a developer in the mainland.

I was very impressed by the teamwork I saw, completely unlike the sort
of back-biting and personalization that goes on both in American
programming offices and on newsgroups like this. The result of the
constant bullying in America is that people labeled "programmers" in
America have had their jobs hollowed-out where they're not laid off,
and they become glorified clerical people who merely send coding
problems on to offshore coders in Asia.

I think it's ugly what's happening here.
 

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,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top