ALTE DOCUMENTE
|
|||||||||
Let's formalize a bit what we are discussing. Here are some tables that you can use as reference tables. We have first the words of the language, the statements. Then we have a dictionary of some sentences you can write with those statements, the different declarations and control-flow constructs. And in the end is the summary of the pre-processor instructions. 656i81g I have tried to put everything hoping that I didn't forget something.
You will find in the left column a more or less formal description of the construct, a short explanation in the second column, and an example in the third. In the first column, this words have a special meaning: "id", meaning an identifier, "type" meaning some arbitrary type and "expr" meaning some arbitrary C expression.
I have forced a page break here so that you can print these pages separately, when you are using the system.
Expression |
Meaning and value of result |
Example |
Identifier |
The value associated with that identifier. (See Identifiers) |
id |
constant |
The value defined with this constant (See Constants). | |
Integer constant. |
45 45L 45LL |
|
Floating constant |
45.9 45.9f |
|
character constant |
'A' L'A' |
|
string literal |
Hello L Hello |
|
Define tables or structure data | ||
Array [index ] |
Access the position "index" of the given array. Indexes start at zero (See array) |
Table[45] |
Array[i1][i2] |
Access the n dimensional array using the indexes i1, i2, . in |
Table[34][23] This access the 35th line, 24th position of Table |
fn ( args ) |
Call the function "fn" and pass it the comma separated argument list "args".(Function Call) |
printf( %d |
fn (arg, ...) | ||
(*fn)(args) |
Call the function whose machine address is in the pointer fn. | |
struct.field |
Access the member of the structure |
Customer.Name |
struct->field |
Access the member of the structure through a pointer |
Customer->Name |
var = value |
Assign to the variable[1] the value of the right hand side of the equals sign. (Assignment) |
a = 45 |
expression++ |
Equivalent to expression = expression + 1. Increment expression after using its value. (See Postfix). |
a = i++ |
expression-- |
Equivalent to expression = expression - 1. Decrement expression after using its value. (See Postfix). |
a = i- |
++expression |
Equivalent to expression = expression+1. Increment expression before using its value. (see Postfix) |
a = ++I |
--expression |
Equivalent to Expression = expression - 1. Decrement expression before using it. (See Postfix) |
a = --i |
& object |
Return the machine address of object. The type of the result is a pointer to object. |
&i |
* pointer |
Access the contents at the machine address stored in the pointer. |
*pData |
- expression |
Subtract expression from zero, i.e. change the sign. |
-a |
~ expression |
Bitwise complement expression. Change all 1 bits to 0 and all 0 bits to 1. |
~a |
! expression |
Negate expression: if expression is zero, !expression becomes one, if expression is different than zero, it becomes zero. |
!a |
sizeof(expr) |
Return the size in bytes of expr. See sizeof. |
sizeof(a) |
(type) expr |
Change the type of expression to the given type. This is called "cast". |
(int *)a |
expr * expr |
Multiply |
a*b |
expr / expr |
Divide |
a/b |
expr % expr |
Divide first by second and return the remainder |
a%b |
expr + expr |
Add |
a+b |
expr1 - expr2 |
Subtract expr2 from expr1. See subtraction. |
a-b |
expr1 << expr2 |
Shift left expr1 expr2 bits. |
a << b |
expr1 >> expr2 |
Shift right expr1 expr2 bits. |
a >> b |
expr1 < expr2 |
1 if expr1 is smaller than expr2, zero otherwise |
a < b |
expr1 <= expr2 |
1 if expr1 is smaller or equal than expr2, zero otherwise |
a <= b |
expr1 >= expr2 |
1 if expr1 is greater or equal than expr2, zero otherwise |
a >= b |
expr1 > expr2 |
1 if expr2 is greater than expr2, zero otherwise |
a > b |
expr1 == expr2 |
1 if expr1 is equal to expr2, zero otherwise |
a == b |
expr1 != expr2 |
1 if expr1 is different from expr2, zero otherwise |
a != b |
expr1 & expr2 |
Bitwise AND expr1 with expr2 |
a&8 |
expr1 ^ expr2 |
Bitwise XOR expr1 with expr2 |
a^b |
expr1 | expr2 |
Bitwise OR expr1 with expr2 |
a|16 |
expr1 && expr2 |
Evaluate expr1. If its result is zero, stop evaluating the whole expression and set the result of the whole expression to zero. If not, continue evaluating expr2. The result of the expression is the logical AND of the results of evaluating each expression. |
a < 5 && a > 0 This will be 1 if "a" is between 1 to 4. If a >= 5 the second test is not performed. |
expr1 || expr2 |
Evaluate expr1. If the result is one, stop evaluating the whole expression and set the result of the expression to 1. If not, continue evaluating expr2. The result of the expression is the logical OR of the results of each expression. |
a == 5 ||a == 3 This will be 1 if either a is 5 or 3 |
expr ? val1:val2 |
If expr evaluates to non-zero (true), return val1, otherwise return val2. See Conditional_operator. |
a= b ? 2 : 3 a will be 2 if b is true, 3 otherwise |
expr *= expr1 |
Multiply expr by expr1 and store the result in expr |
a *= 7 |
expr /= expr1 |
Divide expr by expr1 and store the result in expr |
a /= 78 |
expr %= expr1 |
Calculate the remainder of expr % expr1 and store the result in expr |
a %= 6 |
expr += expr1 |
Add expr1 with expr and store the result in expr |
a += 6 |
expr -= expr1 |
Subtract expr1 from expr and store the result in expr |
a -= 76 |
expr <<= expr1 |
Shift left expr by expr1 bits and store the result in expr |
a <<= 6 |
expr >>= expr1 |
Shift right expr by expr1 bits and store the result in expr |
a >>= 7 |
expr &= expr1 |
Bitwise and expr with expr1 and store the result in expr |
a &= 32 |
expr ^= expr1 |
Bitwise xor expr with expr1 and store the result in expr |
a ^= 64 |
expr |= expr1 |
Bitwise or expr with expr1 and store the result in expr |
a |= 128 |
expr , expr1 |
Evaluate expr, then expr1 and return the result of evaluating the last expression, in this case expr1 |
a=7,b=8 The result of this is 8 |
Expression |
Meaning |
Example |
type identifier; |
Identifier will have the specified type within this scope. See declarations. |
int a; |
type * id; |
Identifier will be a pointer to objects of the given type. You add an asterisk for each level of indirection. A pointer to a pointer needs two asterisks, etc. |
int *pa; pa will be a pointer to integers |
type & id = expr |
Identifier will be a reference to a single object of the given type. References must be initialized immediately after their declaration. See[3] |
int &ra = a; |
type id[expr] |
Identifier will be an array of expr elements of the given type. The expression must evaluate to a compile time constant or to a constant expression that will be evaluated at run time. In the later case this is a variable length array. |
int *ptrArray[56]; Array of 56 int pointers. |
typedef old new |
Define a new type-name for the old type. See typedef. |
typedef unsigned int uint; |
register id |
Try to store the identifier in a machine register. The type of identifier will be equivalent to signed integer if not explicitly specified. See register. |
register int f; |
extern type id |
The definition of the identifier is in another module. |
extern int frequency; |
static type id |
Make the definition of identifier not accessible from other modules. |
static int f; |
struct id |
Define a compound type composed by the enumeration of fields enclosed within curly braces. |
struct coord ; |
type id:n |
Within a structure field declaration, declare "id" as a sequence of n bits of type "type". See bit-fields |
unsigned n:4 n is an unsigned int of 4 bits |
union id ; |
Reserve storage for the biggest of the declared types and store all of them in the same place. See Unions. |
union dd ; |
enum identifier |
Define an enumeration of comma-separated identifiers assigning them some integer value. See enum. |
enum color ; |
const type id |
Declare that the given identifier can't be changed (assigned to) within this scope. See Const. |
const int a; |
unsigned int-type |
When applied to integer types do not use the sign bit. See unsigned. |
unsigned char a = 178; |
volatile type identifier |
Declare that the given object changes in ways unknown to the implementation. |
volatile int hardware_clock; |
type id(arg1,arg2,.) |
Declare the prototype for the given function. See prototypes. |
double sqrt(double x); |
type (*id)(args) |
Declare a function pointer called "id" with the given return type and arguments list |
void (*fn)(int) |
id : |
Declare a label. |
lab1: |
type fn(args) |
Definition of a function with return type <type> and arguments <args> See Function declarations. |
int add1(int x) |
operator opname (args) |
Redefine one of the operators like +, * or others so that instead of doing the normal operation, this function is called instead. |
operator +(Cmp a,Cmp b) |
inline |
This is a qualifier that applies to functions. If present, it can be understood by the compiler as a specification to generate the fastet function call possible, generally by means of replicating the function body at each call site. |
int inline foo(a); |
// commentary |
Double slashes introduce comments up to the end of the line. See Comments. |
// comment |
/*commentary */ |
Slash star introduces a commentary until the sequence star slash */ is seen. See Comments. |
/* comment */ |
#define id expr |
Replace all appearances of the given identifier by the corresponding expression. See preprocessor. |
#define TAX 6 |
#define mac(a,b) |
Define a macro with n arguments. When used, the arguments are lexically replaced within the macro. See preprocessor |
#define max(a,b) ((a)<(b)? |
#undef id |
Erase from the pre-processor tables the identifier. |
#undef TAX |
#include <header> |
Insert the contents of the given file from the standard include directory into the program text at this position |
#include <stdio.h> |
#include "header" |
Insert the contents of the given file from the current directory |
#include foo.h |
#ifdef id |
If the given identifier is defined (using #define) include the following lines. Else skip them. See preprocessor. |
#ifdef TAX |
#ifndef id |
The contrary of the above |
#ifnef TAX |
#if (expr) |
Evaluate expression and if the result is TRUE, include the following lines. Else skip all lines until finding an #else or #endif |
#if (TAX==6) |
#else |
the else branch of an #if or #ifdef |
#else |
#elif |
Abbreviation of #else #if |
#elif |
#endif |
End an #if or #ifdef preprocessor directive statement |
#endif |
defined (id) |
If the given identifier is #defined, return 1, else return 0. |
#if defined(max) |
Token concatenation |
a##b ab |
|
#line nn |
Set the line number to nn |
#line 56 |
#file "foo.c" |
Set the file name |
#file "ff.c" |
#error errmsg |
Show the indicated error to the user | |
#pragma instructions |
Special compiler directives[5] |
#pragma optimize(off) |
_Pragma(str) |
Special compiler directives. This is a C99 feature. |
_Pragma("optimize (off)"); |
__LINE__ |
Replace this token by the current line number | |
__FILE__ |
Replace this token by the current file name | |
__ func__ |
Replace this token by the name of the current function being compiled. |
printf("fn %s\n" __func__); |
STDC |
Defined as 1 |
#if STDC |
__LCC__ |
Defined as 1 This allows you to conditionally include or not code for lcc-win32. |
#if __LCC__ |
if (expression) else |
If the given expression evaluates to something different than zero execute the statements of the following block. Else, execute the statements of the block following the else keyword. The else statement is optional. Note that a single statement can replace blocks. |
while (expression) |
If the given expression evaluates to something different than zero, execute the statements in the block. Else skip them. |
do while (condition); |
Execute the statements in the block, and afterwards test if condition is true. If that is the case, execute the statements again. |
for(init;test;incr) |
Execute unconditionally the expressions in the init statement. Then evaluate the test expression, and if evaluates to true, execute the statements in the block following the for. At the end of each iteration execute the incr statements and evaluate the test code again. See for. |
switch (expression) |
Evaluate the given expression. Use the resulting value to test if it matches any of the integer expressions defined in the 'case' constructs. If the comparison succeeds, execute the statements in sequence beginning with that case statement. If the evaluation of expression produces a value that doesn't match any of the cases and a "default" case was specified, execute the default case statements in sequence. For more details see switch. |
goto label |
Transfer control unconditionally to the given label. |
continue |
Within the scope of a for/do/while loop statement, continue with the next iteration of the loop, skipping all statements until the end of the loop. |
break |
Stop the execution of the current do/for/while loop statement. |
return expression |
End the current function and return control to the calling one. The return value of the function (if any) can be specified in the expression following the return keyword. |
_stdcall |
Use the stdcall calling convention for this function or function pointer: the called function cleans up the stack. See stdcall. |
int _stdcall foo(void); |
__declspec(dllexport) |
Export this identifier in a DLL to make it visible from outside. |
int __declspec(dllexport) foo(int); |
WINVER |
Replace by the version number of the version of windows. This is a #defined symbol containing two bytes: the upper one is the major version, the lower one is the minor version. | |
WIN32 |
#defined as 1 | |
_WIN32 |
#defined as 1 | |
__int64 |
#defined as long long for compatibility reasons with Microsoft's compiler. |
__int64 big; |
| ||
|