Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Thinking in C++: Your thoughts
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
michaelp




PostPosted: Mon Feb 11, 2008 9:26 pm   Post subject: Thinking in C++: Your thoughts

I'm in the process of reading the book/ebook, Thinking In C++, Volume 1, second edition by Bruce Eckel. I'm sure most of you have heard of the book, since it is usually a highly regarded and mentioned C++ book. Now, I have just started to read the book. I read it before (or started) and didn't like it. Not sure why, maybe didn't know enough C++, whatever. But, I'm on the second chapter now, and I realized something: This is an amazing book!
The first chapter has no code in it, which was a reason why I didn't think about it much. But I read through it. Quickly. It was a great read, and I could read it over and over again, gaining something from it every time. It goes very thoroughly into the subject of OOP and how it helps with projects, etc. There is a great section on analysis and design, which talks about phases of a project. The OOP stuff is still great for someone who has or hasn't encountered the subject before.
I've just started the second chapter, and already learned 1 or 2 things. First is that you can use "hex" or "dec" or "oct" to manipulate the output stream to make a hex, dec or oct number appear. And, that you can use char(number) to print an ASCII character. One more thing is that you can use the "system()" call in the <cstdlib> header to call an external .exe. And I have been learning C++ for 8 months now, or something close to that. Starting at the first example, it contains lots to keep you in the book.

Some questions I have though are "Should he be putting "return 0" at the end of the program examples in the book?
And is "int main() {" an okay way to use the braces? Is it just different from what I've seen and used.

Fantastic book, and highly recommended.

Your thoughts on it if you plan to read it, or have read it.
Sponsor
Sponsor
Sponsor
sponsor
OneOffDriveByPoster




PostPosted: Mon Feb 11, 2008 10:19 pm   Post subject: Re: Thinking in C++: Your thoughts

michaelp @ Mon Feb 11, 2008 9:26 pm wrote:
Some questions I have though are "Should he be putting "return 0" at the end of the program examples in the book?
And is "int main() {" an okay way to use the braces? Is it just different from what I've seen and used.
"return 0" is recommended; not required, but some versions of g++ do not know that. With regards to "int main() {", I assume that you are making reference to the '{' being on the same line. It is personal preference related to indentation style.
Cinjection




PostPosted: Mon Feb 11, 2008 10:54 pm   Post subject: Re: Thinking in C++: Your thoughts

If you say that main returns and int, then return a damn int. It's horrible style, if you ask me. The only reason the compiler will even let you do that is so that C++ can be cross-compatible with C. You can't legally leave out the return of any other function, so it's silly for one to leave it out for main.

Just put it in. It's good style and probably a good habit to get into.
Saad




PostPosted: Mon Feb 11, 2008 11:02 pm   Post subject: Re: Thinking in C++: Your thoughts

I think we're forgetting to say why "return 0" is important, "return 0" in your main is a way of telling your OS that the program worked and didn't produce any errors, and thus executed successfully.
michaelp




PostPosted: Tue Feb 12, 2008 6:12 pm   Post subject: RE:Thinking in C++: Your thoughts

Okay. I usually put return 0 at the end of my programs, just wondering why Mr. Bruce Eckel didn't.
So, has anyone here read or looked at the book?
wtd




PostPosted: Tue Feb 12, 2008 6:16 pm   Post subject: RE:Thinking in C++: Your thoughts

The C++ standard does specify, if memory serves, that any main function which doesn't have an explicit return value returns zero.
michaelp




PostPosted: Sun Feb 17, 2008 9:50 pm   Post subject: RE:Thinking in C++: Your thoughts

Okay. I was pretty sure it did, I have heard stuff about the return 0; and that you don't have to explicitly return it. I still do, helps me know when main() is over.
Now around page 200 in the ebook, so much stuff to learn! Learned about using stuff like static_cast and const_cast for typecasting. Interesting stuff. Very Happy
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: