Translation


by Transposh

Coding Best Practices for C – Part – 1

“Hello world” is the first lesson in any language. We always always try to improve our coding knowledge.  But for a professional development we should follow good and generic standards for writing a code. With my experience in C,I understood the fact,that writing a code is not a great thing. But writing a error free code in small span of time and  which can be referred or enhanced by other developers without any confusion makes a perfect code. As I strongly believe, Today’s best solutions becomes tomorrows Best Practices. We need to learn form our mistake and others experience to become perfect.

With this perception I would like to share my experience to enrich your Coding experience.

Here is some standard for coding C that you can follow to get the best result, and can save your life from Reviewer’s comments.

If you have below goals in mind:

  • Code should be robust and error free.
  • Code should be easy to use and understand.
  • Code should be easy to maintain.

This is for you.

Naming Conventions

General:

  • Clear and informative names are one of the best tools for creating easily understandable code. The name of any identifier should   succinctly describe the purpose of that identifier.
  • Avoid abstract names (in a global context) that are likely to be reused by other parts of the system.

File Names:

  • Header(.h) files should have the same name as the .c for header files dedicated to the .c.
  • File names should be made up of a prefix, underscore, base name, period and suffix.  File names should be consistent with the area of the application being modified.  File names should represent the content or role of the file.
  • Header file names should have the extension “.h”.
  • C Implementation (source) file names should have the extension “.c”

Function Names:

  • Function names should reflect what they do or what they return.
  • Do NOT re-use names of functions from the standards libraries (such as printf or strlen).
  • Function names should normally be formed from two parts: an action (verb) and an object (noun) of the action. Exceptions are query functions where the second part is not a noun, but the name should form a “question”.
    eg. GetSystemTime() SetStringLength()

Variable Names:

  • Variable names should be descriptive of the variable’s functions.
  • Constant names should be in all CAPS, with multiple words separated by an underscore, e.g.  MAX_PAGERS.
  • Macros, with or without parameters, should also be in all CAPS.
  • Enumeration constants and global typedef names should be in all CAPS with individual words separated by underscores, e.g. DATA_VALID.


Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Technorati
  • Webnews
  • Digg
  • del.icio.us
  • StumbleUpon
  • Reddit
  • blogmarks
  • Bloglines
  • BlogMemes
  • Ask
  • DZone
  • Blogosphere News
  • De.lirio.us
  • VoteForIt

Tags: , ,

43 Responses to “Coding Best Practices for C – Part – 1”

Comments

  1. forex account says:

    Awsome content, what template do you use in your blog ?

  2. free karaoke software says:

    What tamplate do you use in your blog? Very interesting articles

  3. free palm pre says:

    Excellent article, bookmarked for future referrence

  4. I never comment on blogs, but your awsome content have forced me to to leave some positive feedback

  5. zaklady bukmacherskie says:

    Nice work, your awsome content have forced me to to leave some positive feedback

  6. Delisa Swaim says:

    I just found your blog via Google by luck and must say it’s a very nice site. Will visit this blog again soon! My site is http://www.wordpressrobot.com/amazing-wordpress-plugin

  7. pebrook says:

    Always bear in mind that your own resolution to succeed is more important than any one thing.

  8. What blog script do you use on your site ?

  9. Etwas OT, aber was ich mich immer schon gefragt habe, warum T-Shirt Druck so teuer ist? Ich meine, die ganzen T-Shirt Drucker wollen knapp 20€ für ein normales T Shirt mit meinem eigenen Motiv haben. Ich suche jetzt aktuell für meine Band einen Anbieter, der mir Kleinserien druckt (so 10-20 stk). Kennt da jemand einen preiswerten Anbieter?

  10. Perfume says:

    Who reads papers when they have such a informative website to read. I was really asking myself on this matters so I went to Yahoo, typed my question and voila, here I am. Such a wonderful surprise to get to your site. Thank you for your time and for this great post. Thank you cute search engine for bringing me here.

    Goodbye!

  11. Eli Byon says:

    Actually, this seems a pretty decent blog, and since I’ve contemplated entering the 21st Century, you’re a good source of advice.

  12. I am a great lover! Appreciate your sharing offering this

  13. free magazine websites says:

    Incredible report,I anticipate some more post from you.

  14. Caryn Vanduynhoven says:

    hey,this is Caryn Vanduynhoven,just observed your Blog on google and i must say this blog is great.may I quote some of the writing found in the web site to my local buddies?i am not sure and what you think?anyhow,Thank you!

  15. Cecille Flesch says:

    Howdy there,just observed your web-site when i google something and wonder what webhosting do you use for your wordpress,the speed is more faster than my blog, i really need it.will back to check it out,thank you!

  16. Blaine Barklow says:

    Hello,just identified your web-site when i google something and wonder what web hosting do you use for your blog,the speed is more faster than my website, i really need it.will back to check it out,i appreciate it!

  17. Nanette Dalla says:

    hey,this is Nanette Dalla,just identified your Post on google and i must say this blog is great.may I quote some of the Post found in your website to my local buddies?i’m not sure and what you think?in either case,Many thanks!

  18. I’m not so convinced but nice share.

  19. Thank you for the great article! As mentioned

  20. Mäh Aufgeschoben ist nicht aufgehoben.

  21. Mia Gordy says:

    Denke mal schon.. naja könnte man sich ordentlich informieren bevor man zu solchen Aussagen kommt .

  22. nani says:

    Really the best content and unique too.

  23. This is a exellent resource. Ill be back.

  24. Hey xjlj6izk35g5nz8zqfjt, very interesting post, it really got me thinking. Thank you. ws9tdfjv2y

  25. This is a top quality post. Loving it dude!

  26. free rpg says:

    You certainly should have the spherical associated with applause for the post and much more specifically, your site generally. Very good quality material

  27. Herman Koltz says:

    It is really a great and helpful piece of information. I am glad that you shared this helpful information with us. Please keep us up to date like this. Thanks for sharing.

  28. Well, that could be good, however think about additional choices we’ve got here? Do you mind crafting one more post about these also? Appreciate it!

  29. natural ingredients contained in a patch will be absorbed through the skin, this is the latest technology as a replacement pill. patch is very easy to use especially against people who are allergic to medicines. express this information on to the needy.

  30. would tell the Polish public. Some experts worried that we might hear something

  31. I really wanted to construct a word to say thanks to you for all of the precious instructions you are giving out at this site. My long internet lookup has at the end of the day been paid with wonderful facts and techniques to share with my company. I ‘d point out that most of us site visitors actually are very much endowed to exist in a fantastic community with very many special professionals with great basics. I feel extremely happy to have seen your website page and look forward to really more excellent minutes reading here. Thanks a lot again for a lot of things.

  32. I very much like your site’s blog post and all and i enjoy the theme even the colour but maybe it needs a different feel to it, its been a long time, anyone else think the same?

  33. I enjoyed the site and all but for some reason this page took forever to open, anyone else having the same issue?

  34. Greetings from Carolina! I’m bored to tears at work so I decided to browse your site on my iphone during lunch break. I love the information you present here and can’t wait to take a look when I get home. I’m shocked at how quick your blog loaded on my mobile .. I’m not even using WIFI, just 3G .. Anyhow, very good site!

  35. Hello! This is my 1st comment here so I just wanted to give a quick shout out and tell you I really enjoy reading your blog posts. Can you suggest any other blogs/websites/forums that cover the same topics? Thanks for your time!

Pingbacks & Trackbacks

  1. [...] Best Practices for C – Part – 2Installing EmpathyCoding Best Practices for C – Part – 1Empathy for [...]

  2. Check These Out…

    [...]check below, are some totally unrelated websites to ours, however, they are most trustworthy sources that we use[...]…

Leave a Reply