Sign in

username:

password:



Not a member?

Search Comp.Arch.Embedded



Search tips

embedded by Keywords

68HC11 | 68HC12 | 8051 | 8052 | ARM | ARM7 | Asic | AT91 | AT91RM9200 | Atmel | AVR | AVRStudio | Bootloader | CFP | CompactFlash | Cygnal | Cypress | Dataflash | DSP | eCos | EEPROM | Embedded Linux | Emulator | Endian | Ethernet | Firewire | FPGA | Freescale | GCC | GNUARM | GSM | H8 | HDLC | I2C | Infineon | Interrupts | Java | JTAG | LCD | LED | LPC2000 | MCU | Microchip | MMC | MPLAB | MSP430 | PC104 | PCB | PCI | PCMCIA | PowerPC | Rabbit | RS232 | RS485 | RTOS | SBC | SDRAM | Sensor | SPI | STK500 | UART | UML | USART | USB | Verilog | VHDL | VxWorks | Xilinx

Ads

Discussion Groups

See Also

DSPFPGAElectronics

Discussion Groups | Comp.Arch.Embedded | What coding standard are you using for C?

There are 57 messages in this thread.

You are currently looking at messages 0 to 10.

What coding standard are you using for C? - Geek - 2009-11-04 17:10:00

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();





Re: What coding standard are you using for C? - D Yuniskis - 2009-11-04 18:10:00

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

Re: What coding standard are you using for C? - larwe - 2009-11-04 18:28:00

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

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

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

Re: What coding standard are you using for C? - Rube Bumpkin - 2009-11-04 20:35:00

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();
> 
> 

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

Re: What coding standard are you using for C? - =?iso-8859-1?Q?Leo_Havm=F8ller?= - 2009-11-05 00:05:00

"Geek" <g...@gik.ze> wrote in message 
news:4af1fbe1$0$275$1...@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. 


Re: What coding standard are you using for C? - 42Bastian Schick - 2009-11-05 01:20:00

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 b...@yahoo.com, it's a spam-only account :-)
Use <same-name>@monlynx.de instead !

Re: What coding standard are you using for C? - 2009-11-05 02:40:00

On Thu, 05 Nov 2009 06:20:01 GMT, b...@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.

Re: What coding standard are you using for C? - Boudewijn Dijkstra - 2009-11-05 03:51:00

Op Thu, 05 Nov 2009 08:40:44 +0100 schreef  
<A...@not.at.arargh.com>:
> On Thu, 05 Nov 2009 06:20:01 GMT, b...@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)

Re: What coding standard are you using for C? - Paul Carpenter - 2009-11-05 03:57:00

In article <4...@news.individual.de>, b...@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

Re: What coding standard are you using for C? - 2009-11-05 04:47:00

On Thu, 05 Nov 2009 09:51:31 +0100, "Boudewijn Dijkstra"
<s...@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.

| 1 | 2 | 3 | 4 | 5 | 6 | next