Inconsistent Program Results

R

Randy Howard

This seems quite a basic point, and I doubt a textbook would get it
wrong.

You'd be amazed. There are dozens of books that get it wrong, and
about half of them are written by Herbert Schildt. If you have a book
written by him, return it if you can, otherwise use it to start a fire.
It costs some thought - if you don't have anything useful to return
from main, what int should you return? 0? 1? 19223?

The standard being the ultimate textbook on such things, you return 0,
or EXIT_SUCCESS in such cases.
OK then, I'll try to remember not to typecast malloc in future, though
again it seems very common in all the code I've seen.

Bear in mind that if you are just learning C, you haven't seen much
code yet, and those replying to you and by and large people that have
been looking at both good and bad examples of C for years, in some
cases decades. You were smart enough to find a newsgroup populated by
a core group of extremely competent C programmers. Be smart enough to
listen to their advice as well.
Hah! Now I remember exactly what happened. I started with return(),
got an error, and assumed I had to return(0) instead - this only gave
a warning, but gcc is extremely picky and produces lots of warnings,
so I tend to ignore them.

*sigh* Wrong attitude. gcc is extremely helpful, in that it produces
a lot of warnings that point out problems in your code, which might
/accidentally/ work on a given day, or a given platform, but are just
likely to not work today, or tomorrow, or when the boss comes along for
that all-important demo. Don't ignore them, understand them so that
you can avoid them in future code.
Why is return() a syntax error? That seems
pretty inconsistent with the syntax for calling a non-built-in
function with no arguments.

What's wrong with:

return;

???


Why should the way you call a function have any commonality of syntax
with the way you return from one?
 

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

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,274
Latest member
JessMcMast

Latest Threads

Top