Jump to content
  • Advertisement
Sign in to follow this  
Xloner12

Form and Style C

This topic is 3793 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I haven't made it to classes for c or anything else for that matter and I just wanted to make sure I was on the right track with the style and form I'm using in C. Now my app works and is doing what I want it to do. And it should be said that the app I'm working on right now is not finished in the slightest. I've got some test phrases in there and some data types that might not be used. But I just want people to check and see if there are things that you know should be done a different way or established style and technique that I'm missing. So in that vein I stuck the main.c and my sockOperations h and c file up in the past bin and Wanted to see if people could give it a glance and comment on how it looks. Most of the meat is in the sockOperations.c file at the bottom of the paste. Please take a look if you feel inclined and post some criticism of my code as that is what i'm looking for. Thanks http://gamedev.pastebin.com/m5d5e8d6f

Share this post


Link to post
Share on other sites
Advertisement
The first thing that jumps at me is your usage of the if construct. A good example is
in recvCycleSocket:
    if(error_check == TAG)
{
return(TAG);
}
if(error_check == USEREXIT)
{
return(USEREXIT);
}

Here it makes sense to make that second part read "else if", it generally makes more sense to someone else reading your code (because you're testing the same value) and can also give the compiler a better idea of what you intend.

Share this post


Link to post
Share on other sites
Im planing on making that check alot more commands so Should I instead try switching to a case statement or do the if then/else as you suggested?

Share this post


Link to post
Share on other sites
Both work. It's more a case of readability over anything else, modern compilers will probably generate identical code. I'd go with switch but it's your call.

Share this post


Link to post
Share on other sites
if(error_check == TAG)
{
return(TAG);
}
if(error_check == USEREXIT)
{
return(USEREXIT);
}


You could do this instead:

if (error_check == TAG || error_check == USEREXIT)
return error_check;

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!