Davy wrote:[color=blue]
>
> Hi,
>
> Thank you for your help!
>
> So the "blocks" is a pointer to a dynamic 2-D array, is it?[/color]
No. It is a pointer to an 1D array.
[color=blue]
>
> I am confused with
> " short (*blocks)[64];"[/color]
start at the variable name. Then read to the right until you reach
a ')' or ']'. Continue reading at the left until you hit a '(' or '['
where you continue to the right and so on. (This is called the left/right rule)
blocks blocks is
blocks) oops, stop reading right, continue left
*blocks) blocks is a pointer
(*blocks) oops, stop reading left, continue to the right
(*blocks)[ blocks is a pointer to an array
(*blocks)[64 blocks is a pointer to an array of size 64
(*blocks)[64] oops, stop reading right, continue to the left
short (*blocks)[64] blocks is a pointer to an array of size 64 of short
[color=blue]
> and " short [64] (*blocks);"[/color]
blocks blocks is
blocks) -> left
*blocks) blocks is a pointer
(*blocks) -> right
(*blocks) nothing on the right, continue left
](*blocks) syntax error, there cannot be a '[' at this position
[color=blue]
> and "short *blocks [64];".[/color]
blocks blocks is
blocks [ blocks is an array
blocks [64 blocks is an array of size 64
blocks [64] -> right
* blocks [64] blocks is an array of size 64 of pointer
short * blocks [64] blocks is an array of size 64 of pointer to short
So the first one (used in a program) can be used to build up this data structure
blocks
+---------+ +-------+ ----+
| o----------------->| | |
+---------+ +-------+ |
| | |
^ +-------+
| | | 64 short's
| ...
| | | |
| +-------+ |
| | | |
| +-------+ ----+
|
| ^
| |
| Array of short
|
Pointer to Array of short's
While the third one, can be used to build this:
blocks
+--------+ +-----+
| o-------------------------->| |
+--------+ +-----+ +-----+
| o----------------->| |
+--------+ +-----+ +-----+
| o----------------------------->| |
..... +-----+ +-----+
| o-------------------->| |
+--------+ +-----+ +-----+
| o------------------------------->| |
+--------+ +-----+
^
|
An array of pointers, where each pointer points to a short
--
Karl Heinz Buchegger
kbuchegg@gascad.at