This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/44069] optimization bug initializing from cast array
- From: "paolo dot carlini at oracle dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 11 May 2010 00:44:05 -0000
- Subject: [Bug c++/44069] optimization bug initializing from cast array
- References: <bug-44069-17521@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #3 from paolo dot carlini at oracle dot com 2010-05-11 00:44 -------
Bah... let's see what Richard thinks. Personally, I would have written it like
this in the first place:
#include <iostream>
template <unsigned R, unsigned C>
class M {
public:
M( const double arr[R][C] ) {
for (unsigned r = 0; r < R; ++r)
for (unsigned c = 0; c < C; ++c)
m[r*C+c] = arr[r][c];
}
double operator()(unsigned r, unsigned c) const
{ return m[r*C+c]; }
private:
double m[R*C];
};
template <unsigned R, unsigned C>
std::ostream& operator<<( std::ostream& str, const M<R,C>& m )
{
for (unsigned r = 0; r < R; ++r) {
str << "{" << m(r,0);
for (unsigned c = 1; c < C; ++c)
str << ", " << m(r,c);
str << "}" << std::endl;
}
return str;
}
int main()
{
double vals[4][4] = { { 1, 2, 3, 4 },
{ 5, 6, 7, 8 },
{ 9, 0, 1, 2 },
{ 3, 4, 5, 6 } };
M<4,4> m( vals );
std::cout << m << std::endl;
return 0;
}
--
paolo dot carlini at oracle dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |rguenth at gcc dot gnu dot
| |org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44069