C Style coding standard: All you want to know about

C Style coding standard: All you want to know about

Rate this post

Coding standard makes code writing cleaner and increases readability. C style is one such coding standard that standardizes the way C programs are written.

Every big organization follows this (or some other coding standard). You should start using this if you are an individual programmer right now. Lets understand what it is and what benefits you will get out of this.

What is C style in C programming and why should we use this?

Basically C style is a coding standard for programming languages such as C program or any other programming language. As a beginner when we start coding we never follow this or any kind of coding standard. But at work place or as part of industry standard (usually bigger companies with good CMM value) the C style is very much mandatory. On the other way nobody will force you to follow C style in smaller or startup organizations but as a coder its always a good idea to have clean code.

The C style coding standard basically makes the code look clean and easily understandable.

What is C style and why is it important

What is C style and why is it important

The coding standards define how the code in a program should be written. basically a coding standard guideline enhances the readability of a program.
Meaning:
– How should you start a new line for a statement?
– How to place braces for a bunch of lines of code?
– Should you be starting a line with some spaces or tabs? How many spaces or tabs?
– Should you indent the code after a conditional branch?

For example the following Wikipedia link illustrates how a while loop with braces can be placed in code.
Following link is a K&R style of writing C code.

Observe the below code snippet to understand C style:


    int main(int argc, char *argv[])
    {
        ...
        |
        v
         while (x == y) {
           |
           v
            something();
            somethingelse();
               |
               v
            if (some_error)
       -->      do_correct();
            else
                continue_as_usual();
        }

        finalthing();
        ...
    }

The while () starts after one tab and the code that is there inside the while further starts after another tab.
Further more the if else statements inside the while loop starts after one more tab as compared to the while() statements.

Now see the below code. It is the same code placed above.
does it look good at all ??

int main(int argc, char *argv[])
{
    ...
while (x==y) {
something();
somethingelse();
if (some_error)
do_correct();
else
continue_as_usual();
}
finalthing();
...
}

I think the basic understanding should be clear by now.
If you are more curious to explore more on this then the following link will help you which explains a more detailed C style coding standard guide.

Previous [VIM] Removing new line at the End Of File in VIM
Next Xilinx Interview Questions for Linux Device Driver developer

About author

You might also like

C Programming 0 Comments

Divided By Zero: What Happens When it Occurs on a System

Rate this post “Divided by Zero” exception, what is this? This is a good question and you must know the answer which will lead you to know a system better.

0 Comments

No Comments Yet!

You can be first to comment this post!

Leave a Reply