468,741 Members | 1,576 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,741 developers. It's quick & easy.

constant multidimensional array in a function argument

The following code compiles with a warning message:
passing arg 1 of `use_vector' from incompatible pointer type

How can one correctly pass a multidimensional array (by reference)
expressing that 'use_vector'
is not meant to modify any of the elements.

Thanks
Szabolcs

------------------------------------------------------------
enum { E=3 };
typedef double vector[4];

void use_vector(const vector x[E])
{
}

int main()
{
vector v[E]={0};
use_vector(v);
}
Jun 27 '08 #1
1 1948
Szabolcs Borsanyi <bo******@thphys.uni-heidelberg.dewrites:
The following code compiles with a warning message:
passing arg 1 of `use_vector' from incompatible pointer type
Yes, you have hit a small hole in the way C handles qualified types.
How can one correctly pass a multidimensional array (by reference)
expressing that 'use_vector'
is not meant to modify any of the elements.
Pretty much all you can do is use a cast:

use_vector((const vector *)v);

(or drop the const from the parameter).
enum { E=3 };
typedef double vector[4];

void use_vector(const vector x[E])
{
}

int main()
{
vector v[E]={0};
use_vector(v);
}
--
Ben.
Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by icosahedron | last post: by
3 posts views Thread by Tyrone Slothrop | last post: by
16 posts views Thread by Rehceb Rotkiv | last post: by
14 posts views Thread by Michel Rouzic | last post: by
5 posts views Thread by LittleCake | last post: by
reply views Thread by zhoujie | last post: by
xarzu
2 posts views Thread by xarzu | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.