M
Michael Birkmose
Hi everyone!,
Are pointers to incomplete types allowed in ANSI C?
I can see that pointer arithmic on pointers to incomple types is
impossible, however there are situations where it can be useful:
consider this:
void foo_function(int (*parm)[], int *parm_size);
The idea is that the function takes a pointer to an array with an
unspecified size of ints. Obviously pointer arithmics such as parm+1 is
impossible. However accesing the value of the array pointed to by parm is
possible: (*parm)[42].
The reason for declaring the function like this is that it takes an array
as a parameter, and outputs another array (potentially of a different
size) as a paramter. Therefore the memory pointed to cannot merely be
overwritten or realloced.
The reason for me asking this question is that the program cdecl tells me
that what I am doing is illegal
cdecl>
declare function (pointer to array of int, pointer to int )returning void
Warning: Unsupported in C -- 'Pointer to array of unspecified dimension'
(maybe you mean "pointer to object")
void f(int (*)[], int *)
And I also find it a bit odd that cdecl does not complain about the
following:
cdecl>
declare function (pointer to array of array 10 of int, pointer to int
)returning void
void f(int (*)[][10], int *)
Since an array of array 10 of int, also is an incomplete type? Did I miss
something?
Are pointers to incomplete types allowed in ANSI C?
I can see that pointer arithmic on pointers to incomple types is
impossible, however there are situations where it can be useful:
consider this:
void foo_function(int (*parm)[], int *parm_size);
The idea is that the function takes a pointer to an array with an
unspecified size of ints. Obviously pointer arithmics such as parm+1 is
impossible. However accesing the value of the array pointed to by parm is
possible: (*parm)[42].
The reason for declaring the function like this is that it takes an array
as a parameter, and outputs another array (potentially of a different
size) as a paramter. Therefore the memory pointed to cannot merely be
overwritten or realloced.
The reason for me asking this question is that the program cdecl tells me
that what I am doing is illegal
cdecl>
declare function (pointer to array of int, pointer to int )returning void
Warning: Unsupported in C -- 'Pointer to array of unspecified dimension'
(maybe you mean "pointer to object")
void f(int (*)[], int *)
And I also find it a bit odd that cdecl does not complain about the
following:
cdecl>
declare function (pointer to array of array 10 of int, pointer to int
)returning void
void f(int (*)[][10], int *)
Since an array of array 10 of int, also is an incomplete type? Did I miss
something?