473,320 Members | 1,695 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

const and valarray reference


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]);
}
Jul 19 '05 #1
4 6643
"Jim West" <eg***********@yahoo.com> wrote...

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. 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
Jul 19 '05 #2
In article <o7Ylb.5077$275.10515@attbi_s53>, Victor Bazarov wrote:
"Jim West" <eg***********@yahoo.com> wrote...

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.

Jul 19 '05 #3
In article <sl**************************@jwest.ecen.okstate.e du>, Jim West wrote:

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]);
}


Continuing to follow up my own posts, I the behavior difference
seems to be because the GNU valarray template includes

const _Tp& operator[](size_t) const;

which is missing from the Intel template. I confirmed that this is being
called using the debugger. So, is this a non-standard implementation
of valarray?

Jul 19 '05 #4
"Jim West" <eg***********@yahoo.com> wrote...
In article <sl**************************@jwest.ecen.okstate.e du>, Jim West

wrote:

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]);
}


Continuing to follow up my own posts, I the behavior difference
seems to be because the GNU valarray template includes

const _Tp& operator[](size_t) const;

which is missing from the Intel template. I confirmed that this is being
called using the debugger. So, is this a non-standard implementation
of valarray?


Well, current standard defines element access for std::valarray as

T operator[](size_t) const;
T& operator[](size_t);

So, yes, the one you quoted would be non-standard.

Victor
Jul 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dack | last post by:
Hi, I want to track memory leaks in my application (that is using <valarray>). I used the following code: #define _CRTDBG_MAP_ALLOC #include <stdlib.h> #include <crtdbg.h> But then, when I...
2
by: Jan Callewaert | last post by:
Hi, since I want to specify an extra function for a std::valarray<float>, I want to subclass it: class FVector : public std::valarray<float> { public: FVector() : std::valarray<float>() {}...
3
by: woessner | last post by:
Hi all, I just tried to create a map<int, valarray<int> > and got some really weird behavior. Here's a simple example: int main() { std::map<int, std::valarray<int> > m; std::valarray<int>...
9
by: Jim | last post by:
Hi, I want to declare that that a valarray of a certain name exist at the beginning of some code, but I can't instatiate it until I've read in some parameters later on in a for loop i.e. int...
1
by: toton | last post by:
Hi, I am using vector and similar containers extensively for my project, as well as boost circular_buffer_space_optimized (and adobe circular_queue which is built over vector ). They all work with...
10
by: Chris Forone | last post by:
Hello Group, there is some memberfunc for std::valarray to return a pointer to the first element in the array. How do i use this? Thanx a lot. HAND Chris
5
by: Chris Forone | last post by:
Hello group, g++ (3.4.2, mingw): float init = {1.f, 2.f, 3.f}; std::map<std::string, std::valarray<float mp; mp = std::valarray(init, 3); mp.size(); // should be 3, but IS 0!
2
by: john | last post by:
Hi, in TC++PL3 on page 665, regarding valarray member functions, it is mentioned: "valarray operator-() const; // result= -v for every element // similarly: +, ~, !" I checked the web and...
43
by: john | last post by:
Hi, in TC++PL 3 on pages 674-675 it is mentioned: "Maybe your first idea for a two-dimensional vector was something like this: class Matrix { valarray< valarray<doublev; public: // ... };
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.