Sign in to follow this  
Xloner12

Form and Style C

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this