Jim West said:
The following compiles with g++ 3.3.2, but fails with Intel icc 7.1 with
the error:
asdf.cc(6): error: expression must be an lvalue or a function designator
f1(&arr[0]);
Is this undefined behavior, or have I found a problem with one compiler?
Code sample is:
void f1(const double *);
void f2(const std::valarray<double> &arr) {
f1(&arr[0]);
}
Constant std::valarray's operator[] returns an rvalue. You
cannot take an address of it.
Actually I took it from Stroustrup Third edition. My copy is at
work so I can't give the page number now, but he speceifically
states that since the iterator for valarray is a pointer that
&arr[0] is valid.
What are you trying to accomplish?
Perhaps changing f1 to accept a double const & would help:
void f1(double const&);
void f2(std::valarray<double> const& arr) {
f1(arr[0]);
}
?
Victor
I've written several wrappers to overload basic linear algebra subroutine
(BLAS) Fortran functions so I can call each the same way. An actual code
piece (I guess I should have given this before) is
using std::valarray;
extern "C" void daxpy_(const int &n, const double &Alpha, const double *x,
const int &incx, double *y, const int &incy);
inline void axpy(int n, double Alpha, const valarray<double> &x, int incx,
valarray<double> &y, int incy) {
daxpy_(n, Alpha, &x[0], incx, &y[0], incy); }
I also have versions to overload the other three equivalent BLAS routines
(saxpy_, caxpy_, and zaxpy_). Since they are Fortran routines I need to
send a pointer to the first position of the array. daxpy_ does not
change the data in the x array, so I have been telling the compiler that
by adding the const. Did I get it in the wrong place? (Previously I had
been using new/delete to allocate/deallocate the arrays, but a memory leak
that proved difficult to locate convinced me to use the C++ tools as they
were intentended.)
Your modifications to the test code compiled on both compilers. That
may be the fix that I needed. (Although I don't understand why it is
different from what I had...more reading Stroustrup tomorrow!)
Thanks for the input.