Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Question about syntax preferences

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
HalfPrime
Grandmaster Cheater
Reputation: 0

Joined: 12 Mar 2008
Posts: 532
Location: Right there...On your monitor

PostPosted: Sun Mar 30, 2008 3:12 pm    Post subject: Question about syntax preferences Reply with quote

Using int main instead of void main
saying std::cout, etc instead of using namespace std
banishing system for cin.ignore or getch

I see people recommending these all the time in this section, but I don't understand why one's better than the other.
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Sun Mar 30, 2008 3:23 pm    Post subject: Re: Question about syntax preferences Reply with quote

HalfPrime wrote:
Using int main instead of void main


Only use int main() if you plan on returning a value to a parent process, otherwise you might as well use void main().

HalfPrime wrote:
saying std::cout, etc instead of using namespace std


It is really the same thing, when you declare a namespace that means that every class function coming afterwards is prefixed with that namespace. It is just a coding habit, either one is fine.

HalfPrime wrote:
banishing system for cin.ignore or getch


Use std::cin.ignore(), getch() requires another header.
Back to top
View user's profile Send private message
HalfPrime
Grandmaster Cheater
Reputation: 0

Joined: 12 Mar 2008
Posts: 532
Location: Right there...On your monitor

PostPosted: Sun Mar 30, 2008 10:06 pm    Post subject: Reply with quote

Ah, ok. So there's no real performance difference.

Quote:
Use std::cin.ignore(), getch() requires another header.

Is there anything wrong with system("PAUSE")?
Back to top
View user's profile Send private message
Jani
Grandmaster Cheater
Reputation: 2

Joined: 29 Dec 2006
Posts: 804

PostPosted: Mon Mar 31, 2008 9:44 am    Post subject: Reply with quote

HalfPrime wrote:
Using int main instead of void main
void main isn't acceptable in the C99 standard. Altho the return value of the proggy is from the time of Adam, some platforms still use it. That's why you should always return something from the main function. Also, not all the compilers do know how to handle void main.

HalfPrime wrote:
saying std::cout, etc instead of using namespace std
Including the whole namespace destroys one useful thing of C++. The idea is that you could have n functions with same name, as long as they're in different namespaces.

HalfPrime wrote:
banishing system for cin.ignore or getch.
I'd not even recommend getch, because it is deprecated and _getch isn't supported on all compilers/platforms (it isn't portable). For the system thingy:

HalfPrime wrote:
Is there anything wrong with system("PAUSE")?
Not everyone codes proggies for Windows. And even if you were coding a proggy for Windows, it's not nice to call external stuff >_>
Back to top
View user's profile Send private message
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Mon Mar 31, 2008 9:50 pm    Post subject: Reply with quote

Jumping on with what everyone else is saying, and completely agreeing with Jani here:

In my personal opinion, every single function you code should always return a value. No matter how big or small the function is, or what it says. There will always be a reason why that function can fail. (I know a lot of people will disagree with this, but it is my opinion.) Nothing inside a computer is perfect, and something can cause an error in the most uncommon of places. I prefer to at least use a boolean return, or a hresult, for any function I write unless it needs a different return value.

For the namespace, as Jani said, there is no reason to include the entire namespace in your project. Just wasting resources doing that. Unless you really plan to use like.. every single piece of the namespace in a project, theres no reason for you to include it. Just take the time to type out the std::

System is a resource hog. I bash it because of my own tests as well as numerous articles I have read about how it works and what it does. This is one of my favored articles on the subject:
http://www.gidnetwork.com/b-61.html

You load so much more things into the memory of your program just by calling that 1 line. You are already using the iostream, take advantage of whats already given to you to accomplish the same thing with less of a footprint.

Code:
std::cin.ignore();
std::cin.sync();


The same goes for getch() in this case. It's not a resource thing, but theres no reason to add more includes then what you need when you can pause the console already with the iostream header.

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites