By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,122 Members | 1,554 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,122 IT Pros & Developers. It's quick & easy.

constant multidimensional array in a function argument

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.