Daniel T. wrote:
> benben <benhonghatgmaildotcom@nospam> wrote:
>
> > Gernot Frisch wrote:
> > > Hi,
> > >
> > >
> > > can I somehow do something like this:
> > >
> > > void foo(int*)
> > > {}
> > >
> > > int main()
> > > {
> > > foo( {1,2,3,4} );
> > > return 0;
> > > }
> > >
> >
> > Not in the current standard. You will have to do some workarounds other
> > people have suggested. Seems to me it is very likely that C++0x will get
> > this right finally, but that's like, what, 5 more years from now?
>
> I hope C++0x won't allow the above. Passing a constant array to a
> pointer to non-const would be horrible.
If C++0x would allow it in C99's form, it would look like
void foo(int*)
{}
int main()
{
foo( (int []) {1,2,3,4} );
return 0;
}
which behaves exactly like
void foo(int*)
{}
int main()
{
int dummy[] = {1,2,3,4};
foo(dummy);
return 0;
}
There's no problem with const. You're allowed to modify the data, and
if you don't want to, you have the possibility of writing
(const int []) {1,2,3,4}.
|