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 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 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 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 on other sites
if(error_check == TAG)      {        return(TAG);      }    if(error_check == USEREXIT)      {        return(USEREXIT);      }

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

Create an account

Register a new account

• Forum Statistics

• Total Topics
628282
• Total Posts
2981805

• 9
• 10
• 11
• 17
• 14