C PROGRAMMING

C Programming

Date Published:
Last Modified:

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 Type Promotions
  • Data Types
  • Dynamic Memory Allocation
  • Enumerations
  • File Input And Output
  • Header Guards
  • Inserting Assembly Code Into C
  • Linkage
  • 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
  • Reading User Input
  • Reducing Code Execution Time
  • Standards And Versions
  • String Manipulation
  • Structures
  • Switch Statements
  • System Calls
  • Tips And Tricks
  • Unions
  • Variadic Functions
  • 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 indefintely 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 Lockhead 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. [scribd id=3969122 key=key-2kngufjhmo9zcs93g4mf mode=list] There are programs out there which format and tidy up your code. One such example is AStyle (or Artistic Stylle), a open-source program which is a

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

    Click here to visit their website.

    The C library reference (http://www.cplusplus.com/reference/clibrary/) provides good explanations on standard functions that are included with the C programming language, organised by file and then by function. Also check out the GNU C Pre-processor reference.


    Tags:

      comments powered by Disqus