User`s manual

38 digi.com Language
It is possible to do pointer arithmetic, but this is slightly different from ordinary integer arithmetic. Here
are some examples.
Because the float is a 4-byte storage element, the statement q = p+5 sets the actual value of q to
p+20. The statement q++ adds 4 to the actual value of q. If f were an array of 1-byte characters, the
statement q++ adds 1 to q.
Beware of using uninitialized pointers. Uninitialized pointers can reference ANY location in memory.
Storing data using an uninitialized pointer can overwrite code or cause a crash.
A common mistake is to declare and use a pointer to char, thinking there is a string. But an uninitialized
pointer is all there is.
Pointer checking is a run-time option in Dynamic C. Use the Compiler tab on the Options | Project Options
menu. Pointer checking will catch attempts to dereference a pointer to unallocated memory. However, if an
uninitialized pointer happens to contain the address of a memory location that the compiler has already
allocated, pointer checking will not catch this logic error. Because pointer checking is a run-time option,
pointer checking adds instructions to code when pointer checking is used.
4.16 Pointers to Functions, Indirect Calls
Pointers to functions may be declared. When a function is called using a pointer to it, instead of directly,
we call this an indirect call.
The syntax for declaring a pointer to a function is different than for ordinary pointers, and Dynamic C syn-
tax for this is slightly different than the standard C syntax. Standard syntax for a pointer to a function is:
for example:
Dynamic C doesn’t recognize the argument list in function pointer declarations. The correct Dynamic C
syntax for the above examples would be:
float f[10], *p, *q; // an array and some ptrs
p = &f; // point p to array element 0
q = p+5; // point q to array element 5
q++; // point q to array element 6
p = p + q; // illegal!
char* string;
...
strcpy( string, "hello" ); // Invalid!
printf( string ); // Invalid!
returntype (*name)( [argument list] );
int (*func1)(int a, int b);
void (*func2)(char*);
int (*func1)();
void (*func2)();