Google Mail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
What coding standard are you using for C?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  Messages 1 - 25 of 57 - Collapse all  -  Translate all to Translated (View all originals)   Newer >
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Follow-up To:
Add Cc | Add Follow-up to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers that you hear
 
Geek  
View profile   Translate to Translated (View Original)
 More options 4 Nov, 22:10
Newsgroups: comp.arch.embedded
From: "Geek" <g...@gik.ze>
Date: Wed, 4 Nov 2009 23:10:37 +0100
Local: Wed 4 Nov 2009 22:10
Subject: What coding standard are you using for C?
What coding standard are you using for C (if any)?

Like naming variables, functions, constants, globals, locals, types etc.?

for example:

MyFunction();
myFunction();
My_Function()
my_function()

UART_read()
UartRead()
UARTRead();


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
D Yuniskis  
View profile   Translate to Translated (View Original)
 More options 4 Nov, 23:10
Newsgroups: comp.arch.embedded
From: D Yuniskis <not.going.to...@seen.com>
Date: Wed, 04 Nov 2009 16:10:55 -0700
Local: Wed 4 Nov 2009 23:10
Subject: Re: What coding standard are you using for C?

Geek wrote:
> What coding standard are you using for C (if any)?

> Like naming variables, functions, constants, globals, locals, types etc.?
> for example:

> MyFunction();
> myFunction();
> My_Function()
> my_function()

> UART_read()
> UartRead()
> UARTRead();

You will get as many *different* answers as respondents!  :>
Find one that *you* are comfortable with and be consistent
within that.

Things you might consider:
MaxValue vs. ValueMax -- the latter sorts better with
   names like ValueMin (contrast this with MinValue)
Adding underbars improves readability but lengthens
   identifiers.
If you adopt a naming convention that embeds the type of
   an object in the name of the object (e.g., "Hungarian"
   notation), then you have to change the name of the object
   if you end up changing its type.
Globals are evil.  :>  You might also find limits on globals
   are different (number of characters, etc.)
Decide if you want to be verbose or cryptic with your names.
   E.g., char *p vs. char *ptr vs. char *pointer...


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
larwe  
View profile   Translate to Translated (View Original)
 More options 4 Nov, 23:28
Newsgroups: comp.arch.embedded
From: larwe <zwsdot...@gmail.com>
Date: Wed, 4 Nov 2009 15:28:52 -0800 (PST)
Local: Wed 4 Nov 2009 23:28
Subject: Re: What coding standard are you using for C?
On Nov 4, 6:10 pm, D Yuniskis <not.going.to...@seen.com> wrote:

> You will get as many *different* answers as respondents!  :>

Why so few? Anyone here who works on code of different vintages or for
different platforms is probably working with at least three or four
different styles/standards at once.

My own style (where I am free to choose it) is heavily influenced by
having written code for OS/2 - I prefix all functions and variables
with an abbreviation indicating the module in which they reside, for
example...


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rube Bumpkin  
View profile   Translate to Translated (View Original)
 More options 5 Nov, 01:35
Newsgroups: comp.arch.embedded
From: Rube Bumpkin <Some...@somewhere.world>
Date: Wed, 04 Nov 2009 20:35:11 -0500
Local: Thurs 5 Nov 2009 01:35
Subject: Re: What coding standard are you using for C?

Jack Ganssle has written quite a bit on this in Embedded Systems Design
(Is that their current name?) magazine, his weekly newsletter, and has
info on his website (www.ganssle.com). For example
http://www.ganssle.com/fsm.pdf has a whole lot of ideas about this.

RB


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Leo Havmøller  
View profile   Translate to Translated (View Original)
 More options 5 Nov, 05:05
Newsgroups: comp.arch.embedded
From: Leo Havmøller <rtx...@nospam.nospam>
Date: Thu, 5 Nov 2009 06:05:02 +0100
Local: Thurs 5 Nov 2009 05:05
Subject: Re: What coding standard are you using for C?
"Geek" <g...@gik.ze> wrote in message

news:4af1fbe1$0$275$14726298@news.sunsite.dk...

> What coding standard are you using for C (if any)?

> Like naming variables, functions, constants, globals, locals, types etc.?

Here's a few:
http://www.sourceformat.com/coding-standard.htm

Leo Havmøller.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
42Bastian Schick  
View profile   Translate to Translated (View Original)
 More options 5 Nov, 06:20
Newsgroups: comp.arch.embedded
From: bastia...@yahoo.com (42Bastian Schick)
Date: Thu, 05 Nov 2009 06:20:01 GMT
Local: Thurs 5 Nov 2009 06:20
Subject: Re: What coding standard are you using for C?

On Wed, 4 Nov 2009 23:10:37 +0100, "Geek" <g...@gik.ze> wrote:
>What coding standard are you using for C (if any)?

>Like naming variables, functions, constants, globals, locals, types etc.?

What ever you choose, keep it throughout the project.

>for example:

>MyFunction();
>myFunction();

I myself prefer:
Camel-style starting with lower letter, no type-information in symbols
(i.e. no int *ip_a;).
Types appended with _t, structs with _s and classes with _c. Classes
start with an upper letter.
Pre-processor macros all upper-case and the values always surrounded
by brackets.
E.g.:
#define VALUE (1)
(I just debugged customer code, who did not do this:
#define VALUE 1<<5
And in the code:
        mask &= ~VALUE;
Guess what happened ? :-)

Global functions get a module-prefix separated by "_"
Opening braces are in the line of if/while/for/do/switch, indention 2
spaces.
Code should be readable, so no
if(i==1||i==4)
but
if ( (i == 1) || (i == 4) )
Use spaces, good code should not look like prose rather like poetry.

But of course, writing code for customers forces other styles.
--
42Bastian
Do not email to bastia...@yahoo.com, it's a spam-only account :-)
Use <same-name>@monlynx.de instead !


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
ararghmail911nos...@not.at.arargh.com  
View profile   Translate to Translated (View Original)
 More options 5 Nov, 07:40
Newsgroups: comp.arch.embedded
From: ArarghMail911NOS...@NOT.AT.Arargh.com
Date: Thu, 05 Nov 2009 01:40:44 -0600
Local: Thurs 5 Nov 2009 07:40
Subject: Re: What coding standard are you using for C?
On Thu, 05 Nov 2009 06:20:01 GMT, bastia...@yahoo.com (42Bastian

Schick) wrote:

<snip>
>Pre-processor macros all upper-case and the values always surrounded
>by brackets.
>E.g.:
>#define VALUE (1)

I always thought brackets were []  not () ?

<snip>
--
ArarghMail911 at [drop the 'http://www.' from ->] http://www.arargh.com
BCET Basic Compiler Page: http://www.arargh.com/basic/index.html

To reply by email, remove the extra stuff from the reply address.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Boudewijn Dijkstra  
View profile   Translate to Translated (View Original)
 More options 5 Nov, 08:51
Newsgroups: comp.arch.embedded
From: "Boudewijn Dijkstra" <sp4mtr4p.boudew...@indes.com>
Date: Thu, 05 Nov 2009 09:51:31 +0100
Local: Thurs 5 Nov 2009 08:51
Subject: Re: What coding standard are you using for C?
Op Thu, 05 Nov 2009 08:40:44 +0100 schreef  
<ArarghMail911NOS...@not.at.arargh.com>:

> On Thu, 05 Nov 2009 06:20:01 GMT, bastia...@yahoo.com (42Bastian
> Schick) wrote:
> <snip>
>> Pre-processor macros all upper-case and the values always surrounded
>> by brackets.
>> E.g.:
>> #define VALUE (1)
> I always thought brackets were []  not () ?

Yes and no. There are four main types of brackets:
- round brackets, open brackets or parentheses:  ( )
- square brackets, closed brackets or box brackets:  [ ]
- curly brackets, squiggly brackets, swirly brackets, braces:  { }
- angle brackets, diamond brackets, cone brackets, wickets, chevrons:  < >  
or ⟨ ⟩

http://en.wikipedia.org/wiki/Bracket

--
Gemaakt met Opera's revolutionaire e-mailprogramma:  
http://www.opera.com/mail/
(remove the obvious prefix to reply by mail)


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Paul Carpenter  
View profile   Translate to Translated (View Original)
 More options 5 Nov, 08:57
Newsgroups: comp.arch.embedded
From: Paul Carpenter <p...@pcserviceselectronics.co.uk>
Date: Thu, 5 Nov 2009 08:57:54 -0000
Local: Thurs 5 Nov 2009 08:57
Subject: Re: What coding standard are you using for C?
In article <4af26b51.79767...@news.individual.de>, bastia...@yahoo.com
says...

> On Wed, 4 Nov 2009 23:10:37 +0100, "Geek" <g...@gik.ze> wrote:

> >What coding standard are you using for C (if any)?

> >Like naming variables, functions, constants, globals, locals, types etc.?

Choice of fonts printed can have a bearing avoid the ONE and L
confusions, let alone the zero and letter o confusions. There
are others.

> What ever you choose, keep it throughout the project.

> >for example:

> >MyFunction();
> >myFunction();

My personal preference on that would be how the parntheses are done
always put a space between, even for empty list. Avoids problems
with some fonts the parentheses being confused as a letter eg 0.

> I myself prefer:
....
> Opening braces are in the line of if/while/for/do/switch, indention 2
> spaces.

    More importantly indent with spces the block of code by the
    same amount. Tabs can be different on systems/IDE/editors

> Code should be readable, so no
> if(i==1||i==4)
> but
> if ( (i == 1) || (i == 4) )

My personal method is ensure the opening parentheses for functions,
language construct ( if, while.. ) are by the name. All others spaced
out, so in a complex if( .... ), it becomes easier to spot at a glance
what is a function and what is a variable.

> Use spaces, good code should not look like prose rather like poetry.

Despite C, being free format, avoid too much free format, remembering
that at some time it may well be printed, 300 character lines wrap
very interestingly, if they wrap. Choosing indentation matching
can make following the code easier, even if you have managed
to get the function to fit on one page.

Look up 'obfuscated C' for examples of how not to do things, one
year they had code that compiled correctly but printed out you could
see the code made a picture.

> But of course, writing code for customers forces other styles.

--
Paul Carpenter          | p...@pcserviceselectronics.co.uk
<http://www.pcserviceselectronics.co.uk/>    PC Services
<http://www.pcserviceselectronics.co.uk/fonts/> Timing Diagram Font
<http://www.gnuh8.org.uk/>  GNU H8 - compiler & Renesas H8/H8S/H8 Tiny
<http://www.badweb.org.uk/> For those web sites you hate

    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
ararghmail911nos...@not.at.arargh.com  
View profile   Translate to Translated (View Original)
 More options 5 Nov, 09:47
Newsgroups: comp.arch.embedded
From: ArarghMail911NOS...@NOT.AT.Arargh.com
Date: Thu, 05 Nov 2009 03:47:21 -0600
Local: Thurs 5 Nov 2009 09:47
Subject: Re: What coding standard are you using for C?
On Thu, 05 Nov 2009 09:51:31 +0100, "Boudewijn Dijkstra"

<sp4mtr4p.boudew...@indes.com> wrote:

<snip>
>> I always thought brackets were []  not () ?

>Yes and no. There are four main types of brackets:
>- round brackets, open brackets or parentheses:  ( )
>- square brackets, closed brackets or box brackets:  [ ]
>- curly brackets, squiggly brackets, swirly brackets, braces:  { }
>- angle brackets, diamond brackets, cone brackets, wickets, chevrons:  < >  
>or ? ?

Confusing.  I call them (in the order above) parentheses, brackets,
braces, and angle brackets OR less & greater.

And there is always « » (174 & 175) which I don't call much of
anything.  :-)
--
ArarghMail911 at [drop the 'http://www.' from ->] http://www.arargh.com
BCET Basic Compiler Page: http://www.arargh.com/basic/index.html

To reply by email, remove the extra stuff from the reply address.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
42Bastian Schick  
View profile   Translate to Translated (View Original)
 More options 5 Nov, 09:51
Newsgroups: comp.arch.embedded
From: bastia...@yahoo.com (42Bastian Schick)
Date: Thu, 05 Nov 2009 09:51:54 GMT
Local: Thurs 5 Nov 2009 09:51
Subject: Re: What coding standard are you using for C?
On Thu, 05 Nov 2009 01:40:44 -0600,

ArarghMail911NOS...@NOT.AT.Arargh.com wrote:
>On Thu, 05 Nov 2009 06:20:01 GMT, bastia...@yahoo.com (42Bastian
>Schick) wrote:

><snip>
>>Pre-processor macros all upper-case and the values always surrounded
>>by brackets.
>>E.g.:
>>#define VALUE (1)
>I always thought brackets were []  not () ?

They are still, I was wrong.

--
42Bastian
Do not email to bastia...@yahoo.com, it's a spam-only account :-)
Use <same-name>@monlynx.de instead !


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
RockyG  
View profile   Translate to Translated (View Original)
 More options 5 Nov, 13:59
Newsgroups: comp.arch.embedded
From: "RockyG" <RobertG...@gmail.com>
Date: Thu, 05 Nov 2009 07:59:45 -0600
Local: Thurs 5 Nov 2009 13:59
Subject: Re: What coding standard are you using for C?
>On Thu, 05 Nov 2009 01:40:44 -0600,
>ArarghMail911NOS...@NOT.AT.Arargh.com wrote:

>>On Thu, 05 Nov 2009 06:20:01 GMT, bastia...@yahoo.com (42Bastian
>>Schick) wrote:

>><snip>
>>>Pre-processor macros all upper-case and the values always surrounded
>>>by brackets.
>>>E.g.:
>>>#define VALUE (1)
>>I always thought brackets were []  not () ?

>They are still, I was wrong.

http://en.wikipedia.org/wiki/Bracket

It appears that it depends where you live.

---------------------------------------        
This message was sent using the comp.arch.embedded web interface on
http://www.EmbeddedRelated.com


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tim Wescott  
View profile   Translate to Translated (View Original)
 More options 5 Nov, 15:13
Newsgroups: comp.arch.embedded
From: Tim Wescott <t...@seemywebsite.com>
Date: Thu, 05 Nov 2009 09:13:26 -0600
Local: Thurs 5 Nov 2009 15:13
Subject: Re: What coding standard are you using for C?

Yes.  They changed their name from one that made you think you could read
minds to one that made you worry about sparks destroying what you were
working on.

Dunno why...

--
www.wescottdesign.com


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Rich Webb  
View profile   Translate to Translated (View Original)
 More options 5 Nov, 15:48
Newsgroups: comp.arch.embedded
From: Rich Webb <bbew...@mapson.nozirev.ten>
Date: Thu, 05 Nov 2009 10:48:24 -0500
Local: Thurs 5 Nov 2009 15:48
Subject: Re: What coding standard are you using for C?
On Thu, 05 Nov 2009 09:13:26 -0600, Tim Wescott <t...@seemywebsite.com>
wrote:

IIRC, back when they were still Embedded Systems Programming, a rival
magazine started up with the title Embedded Systems Design. This was,
oh, a decade or so ago? Perhaps a bit less.

Anyway, the old ...Design faded out after a while. It was never quite as
beefy as ...Programming and there was always the confusion with the
phone calls "Would you like a free subscription to Embedded Systems
Design?" "Er, I already have one." "No, no, not that one, we're the
other one." "Oh. Ooookay..."

After the original ESD left the scene (or were bought out?), I'd guess
that ESP decided that "Programming" sounded too limiting and didn't
encompass all the other aspects and so ... voila!

--
Rich Webb     Norfolk, VA


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
D Yuniskis  
View profile   Translate to Translated (View Original)
 More options 5 Nov, 16:35
Newsgroups: comp.arch.embedded
From: D Yuniskis <not.going.to...@seen.com>
Date: Thu, 05 Nov 2009 09:35:16 -0700
Local: Thurs 5 Nov 2009 16:35
Subject: Re: What coding standard are you using for C?

42Bastian Schick wrote:
> On Wed, 4 Nov 2009 23:10:37 +0100, "Geek" <g...@gik.ze> wrote:

>> What coding standard are you using for C (if any)?

>> Like naming variables, functions, constants, globals, locals, types etc.?

> What ever you choose, keep it throughout the project.

If you can *impose* your standard on others, you'll need
a tool to verify compliance "mechanically".  If you *can't*
impose your standard on others, you are best to confer with
them beforehand and try to come to some concensus as to
what you will *all* agree to adopt.

Whatever you do, don't sweat the "appearance" details
(which seems to be the basis of most holy ways on the subject).
Agree on naming conventions, standards for commentary,
how aggressive/pedantic you want run-time checks to be,
etc. and let some tool (e.g., indent) handle the formatting
of the code for you -- everyone can view it however they
like, mainatin it and, when next checked out of the
repository, it gets redressed to suit the style preferences of
its latest beholder!  :>


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Uniden  
View profile   Translate to Translated (View Original)
 More options 5 Nov, 16:37
Newsgroups: comp.arch.embedded
From: Uniden <uni...@nospam.net>
Date: Thu, 5 Nov 2009 10:37:12 -0600
Local: Thurs 5 Nov 2009 16:37
Subject: Re: What coding standard are you using for C?
In article <4692a7d1-0a5e-469f-8731-15147acefc79
@m1g2000vbi.googlegroups.com>, zwsdot...@gmail.com says...

> On Nov 4, 6:10 pm, D Yuniskis <not.going.to...@seen.com> wrote:

> > You will get as many *different* answers as respondents!  :>

> Why so few? Anyone here who works on code of different vintages or for
> different platforms is probably working with at least three or four
> different styles/standards at once.

> My own style (where I am free to choose it) is heavily influenced by
> having written code for OS/2 - I prefix all functions and variables
> with an abbreviation indicating the module in which they reside, for
> example...

I'm in near-violent agreement with you. :-D

I "saw the light" with Steve Oualline's book "C Elements of Style".

<http://www.amazon.com/Elements-Style-Programmers-Elegant-
Programs/dp/1558512918/ref=sr_1_1?ie=UTF8&s=books&qid=1257438680&sr=8-1>

When I read that I learned that writing code is much more than just
hacking out code that only works. Quality comes from communication.

Other books you could ponder: C Style - David Straker and C++ Coding
Standards - Sutter.

<http://www.amazon.com/Style-Guidelines-Programming-Professional-
Programmers/dp/0131168983/ref=sr_1_1?ie=UTF8&s=books&qid=1257438880&sr=
1-1>

<http://www.amazon.com/Coding-Standards-Rules-Guidelines-
Practices/dp/0321113586/ref=sr_1_1?ie=UTF8&s=books&qid=1257438943&sr=1-
1>


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
D Yuniskis  
View profile   Translate to Translated (View Original)
 More options 5 Nov, 16:45
Newsgroups: comp.arch.embedded
From: D Yuniskis <not.going.to...@seen.com>
Date: Thu, 05 Nov 2009 09:45:02 -0700
Local: Thurs 5 Nov 2009 16:45
Subject: Re: What coding standard are you using for C?

Paul Carpenter wrote:
>> Use spaces, good code should not look like prose rather like poetry.

> Despite C, being free format, avoid too much free format, remembering
> that at some time it may well be printed, 300 character lines wrap
> very interestingly, if they wrap. Choosing indentation matching
> can make following the code easier, even if you have managed
> to get the function to fit on one page.

There is also a style issue about the language constructs that
you use as idioms, of a sort.  This can affect indents in subtle
ways (being the type that uses verbose identifiers, each level
of indentation has a big impact on the length of identifier
that can be employed without ending up with a "too long" line).

For example, I like to use bogus do-while's to encapsulate
sections of code that I can *break* out of (continue can be
a friend as well) instead of lots of nested conditionals
or <gasp> a "goto".  But, each costs me a level of indent.  :<

Comment styles can also waste a lot of maintenance effort.
E.g., using comments "alongside" lines of code ends up
lengthening the line of text *and*, when the code snippet
gets "wider", the comment gets pushed further into the
margin requiring a rewrite to "make it fit, again".
So, write comments *above*/below code fragments instead
of alongside (unless they are very short or you are
commenting table entries, argument list in function prototypes,
etc.)


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
D Yuniskis  
View profile   Translate to Translated (View Original)
 More options 5 Nov, 17:48
Newsgroups: comp.arch.embedded
From: D Yuniskis <not.going.to...@seen.com>
Date: Thu, 05 Nov 2009 10:48:48 -0700
Local: Thurs 5 Nov 2009 17:48
Subject: Re: What coding standard are you using for C?

Uniden wrote:
> I "saw the light" with Steve Oualline's book "C Elements of Style".

> When I read that I learned that writing code is much more than just
> hacking out code that only works. Quality comes from communication.

I think the *biggest* advantage of a "coding standard" comes
from consistency.  If someone "following you" (i.e. in the
maintenance process) can learn to *recognize* what you are
doing just by the way you are doing it (choices of identifiers,
programming constructs used, etc.) then their chance of
accurately understanding the intent and mechanism is
greatly increased.

E.g., if you look through my code and see lots of while loops
and then "suddenly" see a do-while, it gives you reason to
pause -- "why has he opted to abandon his established 'style'
in this instance?".

OTOH, if you never do the same thing the same way, the reader
is always "starting from zero" each time he encounters a new
stanza in your code...


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
ChrisQ  
View profile   Translate to Translated (View Original)
 More options 5 Nov, 18:02
Newsgroups: comp.arch.embedded
From: ChrisQ <m...@devnull.com>
Date: Thu, 05 Nov 2009 18:02:08 +0000
Local: Thurs 5 Nov 2009 18:02
Subject: Re: What coding standard are you using for C?

The first thing is to find a good 132 column editor with rectangular cut
and paste and with tabs set to 4 or so spaces. I know that sounds a bit
oblique, but you need to be able to keep a view of the big picture at
all times and weedy ide or even 80 col editors can make this hard work.
How often are the comments and code all over the place in indent terms,
because some team members use tab stops and others use spaces ?. 132 col
editor also means you can indent all comments to the left of the line of
code that it relates to and not jumbled up at odd places in the code,
making it unreadable. I spend most coding time in front of an editor, so
it's arguably the most important tool in the box.

Style can be a very contentious issue and everyone develops their own
over the years, where this is not imposed. I use a modified hungarian
notation for all prototypes and variables, with no single letter vars.
Meaningfull names in all cases and a mixture of upper and lower case to
delimit. I nearly always need to know the size of a variable and doing
that is a prompt to think about the required range. Also, the first few
chars to indicate module. Type defines and defines are all upper case. I
use the misra guidelines in terms of a reliable subset of C to use. I
don't agree with or adhere to everything in it, but it seems like an
honest attempt to bring some order to the chaos. Oh yes, opening and
closing braces for all conditional expressions, even where there is only
a single following line of code. For me, making it look neat and tidy
improves clarity and results in better code because of the slower pace.
It's an intrinsic part of the process that often results incode that
works first time. Finally, module scope shared vars, fine, but declared
static. Strict rule otherwise of no globals at all other than for ro
const data, which is often defined in a separate module anyway.

There's more, but have probably said enough already to get well flamed,
so will stop now :-)...

Regards,

Chris


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Paul E Bennett  
View profile   Translate to Translated (View Original)
 More options 5 Nov, 21:03
Newsgroups: comp.arch.embedded
Follow-up To: comp.arch.embedded
From: Paul E Bennett <Paul_E.Benn...@topmail.co.uk>
Date: Thu, 05 Nov 2009 21:03:59 +0000
Local: Thurs 5 Nov 2009 21:03
Subject: Re: What coding standard are you using for C?

Geek wrote:
> What coding standard are you using for C (if any)?

[%X]

Whatever standard you end up following or imposing be consistent. I would
say you should have a whole series of standards within your company for
document layout, use of common identities, as well as software coding
standards. Use plenty of technical reviews throughout the development
process and enforce all your standards. Also, be aware of the dangers of
some constructs. MISRA-C guidelines are useful if you need to do dependable
development.

Alternatively you could also look at your language choices. ;>

--
********************************************************************
Paul E. Bennett...............<email://Paul_E.Benn...@topmail.co.uk>
Forth based HIDECS Consultancy
Mob: +44 (0)7811-639972
Tel: +44 (0)1235-510979
Going Forth Safely ..... EBA. www.electric-boat-association.org.uk..
********************************************************************


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
David Brown  
View profile   Translate to Translated (View Original)
 More options 5 Nov, 21:29
Newsgroups: comp.arch.embedded
From: David Brown <david.br...@hesbynett.removethisbit.no>
Date: Thu, 05 Nov 2009 22:29:29 +0100
Local: Thurs 5 Nov 2009 21:29
Subject: Re: What coding standard are you using for C?

Before fixing on a particular style, you have to decide *why* you are
doing so.  Sometimes you have specific requirements (if your customer
specifies MISRA, you use MISRA).  And sometimes you are working on
existing code, in which case fitting with the existing style is often
the best choice.  But mostly you or your company pick a style to make
your code easy to read, easy to understand, easy to maintain, and to
lower the risks of mistakes.  Those are the goals to keep in mind when
picking the style.  You also have to take into consideration who is
writing the code, and what kind of code you are writing.  One style does
not fit all.

Personally, I think that rigid naming patterns are unnecessary, and can
often be ugly.  A great many people are convinced that pre-processor
macros should always be in all caps.  I think that convention should
have died out 25 years ago when computers got "caps lock" keys.  Some
people like to use Hungarian notation (stuff like "ucLength" for an
unsigned char variable).  I don't - it discourages use of appropriate
types.  The exact size of a variable should be either clear, or
irrelevant, and you see it from the declaration of the variable, not
from its name.  But that's for /my/ programming - the style you want
should suit /your/ programming.

One thing that I think is particularly important is code spacing,
indenting and layout.  I'm not nearly as permissive there - blocks must
always be indented consistently.  I also insist on braces with
multi-line if's - if something takes more than one line, it's a block
and should have braces and indents.


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Vladimir Vassilevsky  
View profile   Translate to Translated (View Original)
 More options 5 Nov, 21:47
Newsgroups: comp.arch.embedded
From: Vladimir Vassilevsky <nos...@nowhere.com>
Date: Thu, 05 Nov 2009 15:47:47 -0600
Local: Thurs 5 Nov 2009 21:47
Subject: Re: What coding standard are you using for C?

Geek wrote:
> What coding standard are you using for C (if any)?

> Like naming variables, functions, constants, globals, locals, types etc.?

> for example:

> MyFunction();
> myFunction();
> My_Function()
> my_function()

> UART_read()
> UartRead()
> UARTRead();

Just don't write assembly code in capital letters and do fill tabs with
spaces. Then you will be fine.

Vladimir Vassilevsky
DSP and Mixed Signal Design Consultant
http://www.abvolt.com


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Didi  
View profile   Translate to Translated (View Original)
 More options 5 Nov, 22:23
Newsgroups: comp.arch.embedded
From: Didi <d...@tgi-sci.com>
Date: Thu, 5 Nov 2009 14:23:11 -0800 (PST)
Local: Thurs 5 Nov 2009 22:23
Subject: Re: What coding standard are you using for C?
On Nov 5, 11:47 pm, Vladimir Vassilevsky <nos...@nowhere.com> wrote:

> .....

> Just don't write assembly code in capital letters and do fill tabs with
> spaces. Then you will be fine.

ROFL, Vladimir, that was good.

Dimiter


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
s0lstice  
View profile   Translate to Translated (View Original)
 More options 6 Nov, 08:22
Newsgroups: comp.arch.embedded
From: s0lstice <wp.mar...@googlemail.com>
Date: Fri, 6 Nov 2009 00:22:04 -0800 (PST)
Local: Fri 6 Nov 2009 08:22
Subject: Re: What coding standard are you using for C?
On Nov 5, 6:02 pm, ChrisQ <m...@devnull.com> wrote:
<snip>

> The first thing is to find a good 132 column editor with rectangular cut
> and paste and with tabs set to 4 or so spaces. I know that sounds a bit
> oblique, but you need to be able to keep a view of the big picture at
> all times and weedy ide or even 80 col editors can make this hard work.
> How often are the comments and code all over the place in indent terms,
> because some team members use tab stops and others use spaces ?.

They are all over the place because people insist on redefining the
TAB character, supported by misguided editors. TAB stops are every 8
characters. Indent by 4 or 2 spaces, or whatever you want, but TABs
are equivalent to 8 spaces.

<snip>


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
ChrisQ  
View profile   Translate to Translated (View Original)
 More options 6 Nov, 15:46
Newsgroups: comp.arch.embedded
From: ChrisQ <m...@devnull.com>
Date: Fri, 06 Nov 2009 15:46:25 +0000
Local: Fri 6 Nov 2009 15:46
Subject: Re: What coding standard are you using for C?

s0lstice wrote:

> They are all over the place because people insist on redefining the
> TAB character, supported by misguided editors. TAB stops are every 8
> characters. Indent by 4 or 2 spaces, or whatever you want, but TABs
> are equivalent to 8 spaces.

Guilty as charged, but because I use the tab key for indenting. I know
you can can get auto indent from the editor, but prefer not to use it.
Spaces for tabs is much more the lowest common denominator and comes out
looking the same whatever editor it's loaded into and also when printing.

Even trying to get agreement on something as simple as that can be an
uphill struggle, which is why i'm moving over to the idea that an
enforced set of coding standards, perhaps agreed by the team, is the
least hassle way to develop. I don't think it needs to be too rigid, but
a common framework is beneficial. Once you get over the initial afront
about the fact you can't do it all your own way, you find that it works
quite well.

Above all, peer group review is the way to kick out all the clunky ideas
and poor standards, but many companies only pay lip service to the idea.
Takes up far too much time :-(...

Regards,

Chris


    Reply    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Messages 1 - 25 of 57   Newer >
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google