Intuitive C Reference

Intuitive C is a programming language that can be used to develop Intuitive Media Applications. It is similar to the original C language, so if you are familiar with programming in C, you will feel comfortable using Intuitive C.

C Syntax
    Data structures
        Primitive data types
        Arrays
        Structures
    Operators
        Operator precedence
        Arithmetic operators
        Comparison operators
        Bitwise operators
        Other operators
    Control structures
        Compound statements
        Selection statements
        Iteration statements
        Jump statements
    Functions
        Syntax
        Global structure
        Argument passing


C Syntax


Data structures

Primitive data types

Integral type
Integral data type stores numbers in the set of integers. The integral type is int. It stores integer values in 4 bytes (32 bits). The minimum value is -2,147,483,648, the maximum is 2,147,483,647. The following line of code declares an integer variable called i:
  int i;  

Integer variables can be initialized with a value in the following form:
  int i = 4;  

Enumerated type
The enumerated type in Intuitive C, specified with the enum keyword, is a type designed to represent values across a series of named constants. Each of the enumerated constants has type int. An enumerated type is declared with the enum specifier, a name for the enum, and a list of one or more constants contained within curly braces and separated by commas. By default, the first constant in an enumeration is assigned value zero, and each subsequent value is incremented by one over the previous constant. Specific values may also be assigned to constants in the declaration, and any subsequent constants without specific values will be given incremented values from that point onward.
For example, consider the following declarations:
  enum Colors { RED, GREEN, BLUE = 4, YELLOW };  
  Colors paint;  
Which declare the enum Colors type, the int constants RED whose value is zero, GREEN whose value is one, BLUE whose value is four, YELLOW whose value is five and the enum Colors variable paint.

Floating point type
The floating point form is used to represent numbers with a fractional component. They do not however represent most rational numbers exactly; they are a close approximation instead. The floating point type is float. It represents values in the IEEE 754 format. The size of this data type is 4 bytes (32 bits). The following lines of code declare floating point variables:
  float f;  
  float g = 1.72;  

Arrays

Array declaration
Arrays are used to represent structures of consecutive elements of the same type. The declaration of a fixed size array has the following syntax:
  int array [100];  
which defines an array named array to hold 100 values of the primitive type int.

Accessing elements
To access the i- indexed element of array, the syntax would be
  array [i];  
which refers to the value stored in that array element. Array subscript numbering begins at 0. The largest allowed array subscript is therefore equal to the number of elements in the array minus 1.

Multidimensional arrays
Intuitive C supports arrays of multiple dimensions, which are stored in row-major order. Technically, multidimensional arrays are just one-dimensional arrays whose elements are arrays. The syntax for declaring multidimensional arrays is as follows:
  int array [3][4];  
This defines a two-dimensional array with 3 rows and 4 columns. To access an element in this multidimensional array, use
  array [1][2];  
Arrays up-to 4 dimensions can be decalred.

Initializing arrays
Arrays can be initialized in the following form:
  int array1 [2] = { 10, 20 };  
  float array2 [2][4] = { { 1.0, 2.0 }, { 3.0, 4.0 } };  
The number of initializers may be less than the number of elements in the array, in this case the values of the remaining elements are undefined until assigned.

Structures

Structure declaration
Structures are defined as data containers consisting of a sequence of named members of various types. The members of a structure are stored in consecutive locations in memory, although the compiler is allowed to insert padding between or after members (but not before the first member) for efficiency. The size of a structure is equal to the sum of the sizes of its members, plus the size of the padding. Structures are declared with the struct keyword. The specifier keyword is followed by an identifier name, which is used to identify the form of the structure. The identifier is followed by the declaration of the structure's body: a list of member declarations, contained within curly braces, with each declaration terminated by a semicolon. For example, the following statement declares a structure named MyStruct that contains two members:
  struct MyStruct {  
    int i;  
    float f;  
  };  
The following statement will declare the variable s as an instance of structure MyStruct.
  MyStruct s;  

Initializing structures
Structures can be initialized in the following form:
  MyStruct s = { 10, 20.0 };  
The number of initializers may be less than the number of elements in the structure, in this case the values of the remaining elements are undefined until assigned.


Operators

Operator precedence

Operators are listed top to bottom in descending precedence and operators that are on the same row are evaluated with the same precedence, in the given direction.
OperatorsDescriptionDirection
()Function callLeft to right
[]Array subscriptingLeft to right
.Element selectionLeft to right
-Unary minusRight to left
* /Multiplication and divisionLeft to right
< <= > >=Less, Less or equal, Greater, Greater or equalLeft to right
== !=Equal, Not equalLeft to right
=AssignmentRight to left
+= -=Assignment by addition and subtractionRight to left
%= /=Assignment by multiplication and divisionRight to left

Arithmetic operators

Operator nameSyntaxValid types
Additiona + bint, float
Assignment by additiona += bint, float
Unary minus-aint, float
Subtractiona - bint, float
Assignment by subtractiona -= bint, float
Multiplicationa * bint, float
Assignment by multiplicationa *= bint, float
Divisiona / bint, float
Assignment by divisiona /= bint, float

Comparison operators

Operator nameSyntaxValid types
Less thana < bint, float
Less than or equal toa <= bint, float
Greater thana > bint, float
Greater than or equal toa >= bint, float
Not equal toa != bint, float
Equal toa == bint, float

Bitwise operators

Operator nameSyntaxValid types

Other operators

Operator nameSyntaxValid types
Assignmenta = bint, float
Function calla ()functions
Array subscripta [b]arrays
Membera.bstructures


Control structures

Compound statements

Compound statements have the following form:
  {  
    <optional-declaration-list>  
    <optional-statement-list>  
  }  
Compound statements are used as the body of a function or anywhere that a single statement is expected. The declaration-list declares variables to be used in that scope, and the statement-list are the actions to be performed. Note that brackets define their own scope, and variables defined inside those brackets will be automatically deallocated at the closing bracket.

Selection statements

The if statement has the following form:
  if (<expression>)  
    <statement1>  
  else  
    <statement2>  
In the if statement, if the <expression> in parentheses is nonzero (true), control passes to <statement1>. If the else clause is present and the <expression> is zero (false), control will pass to <statement2>. The else <statement2> part is optional, and if absent, a false <expression> will simply result in skipping over the <statement1>. An else always matches the nearest previous unmatched if; braces may be used to override this when necessary, or for clarity.

Iteration statements

Intuitive C has three forms of iteration statement:
  do  
    <statement>  
  while (<expression>);  
  while (<expression>)  
    <statement>  
  for (<expression>; <expression>; <expression>)  
    <statement>  
In the while and do statements, the substatement is executed repeatedly so long as the value of the expression remains nonzero (true). With while, the test, including all side effects from the expression, occurs before each execution of the statement; with do, the test follows each iteration. Thus, a do statement always executes its substatement at least once, whereas while may not execute the substatement at all.
If all three expressions are present in a for, the statement
  for (e1; e2; e3)  
    s;  
is equivalent to
  e1;  
  while (e2) {  
    s;  
    e3;  
  }  
except for the behavior of a continue; statement (which in the for loop jumps to e3 instead of e2). Any of the three expressions in the for loop may be omitted. A missing second expression makes the while test always nonzero, creating a potentially infinite loop.

Jump statements

A function returns to its caller by the return statement. When return is followed by an expression, the value is returned to the caller as the value of the function.
For example:
  return;  
  return a + b;  


Functions

Syntax

A function definition consists of a return type (void if no value is returned), a unique name, a list of parameters in parentheses, and various statements. A function with non-void return type should include at least one return statement:
  <return-type> functionName (<parameter-list>)  
  {  
    <statements>  
    return <expression of type return-type>;  
  }  
where <parameter-list> of N variables is declared as data type and variable name separated by a comma:
  <data-type> var1, <data-type> var2, ... <data-type> varN  

Global structure

Argument passing



© 2008 Intuitive Computers. All rights reserved.