The information in this article applies to:
SUMMARYIn some situations you may need to cast a pointer or an address to a type that is equivalent to a multidimensional array. The following example demonstrates such a situation:
Casting the variable "ptr" to the array type "Arr2Dim" is not correct. The
Microsoft C Compiler displays the following error message:
The correct procedure is to cast the pointer "ptr" to a pointer type equivalent to the array type Arr2Dim. This pointer type can be defined as follows:
Casting "ptr" to the type of "Ptr2Dim", as follows, is correct and produces
no warning messages when compiled at warning level 3:
The address (or pointer) passed to the function is used correctly.
MORE INFORMATIONA similar solution may be applied to the problem of dynamically allocating a multidimensional array. For example, the following code fragment allocates a memory block, which can be used as a 10 x 20 x 30 three- dimensional array:
After the allocation, "ptr3arr" can be used as a three-dimensional array,
as follows, provided i, j, and k are integers within the proper range:
Additional query words:
Keywords : kbLangC kbVC100 kbVC150 kbVC151 kbVC152 kbVC200 kbVC210 kbVC400 kbVC500 kbVC600 |
Last Reviewed: July 1, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |