C PROGRAMMING

# C Programming

## Child Pages

• .bss Section
• Arithmetic Operators
• Arrays
• Assertions (assert())
• Bit Fields And Bit Manipulation/Masking
• C Naming Conventions
• C Related File Extensions
• Comma Operator
• Commenting And Documentation
• Common C Compile/Build Errors
• Control Statements
• Data Types
• Dynamic Memory Allocation
• Enumerations
• File Input And Output
• Inserting Assembly Code Into C
• Linux Bash Commands For C
• Local Jumps (goto)
• Logical Operators
• Non-local Jumps (setjmp(), longjmp())
• Object-Orientated C
• Pointers
• Portability
• Preprocessor
• Processing Command-Line Input
• Reducing Code Execution Time
• Standards And Versions
• String Manipulation
• Structures
• Switch Statements
• System Calls
• Unions
• ## Overview

This is the main parent page for C programming. The information in the following child pages is mostly geared towards C programming in an embedded environment, although there are some parts dedicated to programming on Linux and other environments.

## Endless Loops

Endless loops are usually used in embedded programming for the main function. They are used to keep the code running continuously, since exiting the main function from most embedded systems is undefined (and why would you want to?). In a non-scheduler based environment (i.e., no operating system), it is commonly called the “main loop”. The only code not placed inside (or called from) the main loop is the initialisation code and interrupt handlers. Two common ways of making an endless loop are:

// Endless loop method one (1 could be replaced by a similar constant, such as true)
while(1) {
// Put code here
}

// Endless loop method two
for(;;) {
// Put code here
}

// A code trap is an endless loop with no executable code inside it.
// It causes the processor to halt indefinitely at the statement
// and is good for debugging. It is commonly written like this
while(1);
// or this
for(;;);


In an embedded operating system based environment, there may be more than one endless loop. Typically, there is one per concurrent task or process (such as with FreeRTOS). An interrupt driven scheduler controls which loop the processor is currently executing by changing the CPU's instruction pointer.

## Coding Standards

The Joint Strike Fighter C++ Coding Standards (semi-applicable to C also). Created by Lockheed Martin. A bit of a hefty read (I would never read this cover-to-cover unless I had too), but there is some good stuff in there. It can be viewed here.

There are programs out there which format and tidy up your code. One such example is AStyle (or Artistic Style), a open-source program which is a:

...source code indenter, formatter, and beautifier for the C, C++, C# and Java programming languages