C PROGRAMMING

C Programming

Article by:
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 Types
  • Dynamic Memory Allocation
  • Embedded Systems And The Volatile Keyword
  • 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
  • Processing Command-Line Input
  • Reading User Input
  • Reducing Code Execution Time
  • Standards And Versions
  • String Manipulation in C
  • Structures
  • Switch Statements
  • System Calls
  • The C Preprocessor
  • The Confusing Differences Between struct and typedef struct
  • 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:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    
    // 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

    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.


    Authors

    Geoffrey Hunter

    Dude making stuff.

    Creative Commons License
    This work is licensed under a Creative Commons Attribution 4.0 International License .

    Related Content:

    Tags

    comments powered by Disqus