Re: const and valarray reference

From: Victor Bazarov (v.Abazarov_at_attAbi.com)
Date: 10/23/03


Date: Thu, 23 Oct 2003 21:55:32 GMT


"Jim West" <eggplantparts@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



Relevant Pages

  • Re: const and valarray reference
    ... > Is this undefined behavior, or have I found a problem with one compiler? ... > Code sample is: ... seems to be because the GNU valarray template includes ...
    (comp.lang.cpp)
  • Re: Is this valid C statement?
    ... > Unless the type name specifies a void type, ... >any constraint), but it invokes undefined behavior, since the standard ... The ones the compiler can detect. ... They may diagnose them, but typically only if the user ...
    (comp.lang.c)
  • Re: whats wrong with atof() and casting?
    ... The return type of the function was int, ... Since atofDOES NOT return an int, this is wrong and undefined behavior. ... Note that a compiler is not required to do anything at all when you ... There is no requirement in the C standard that they do. ...
    (comp.lang.c)
  • Re: [Lit.] Buffer overruns
    ... > to the C standard, ... > compiler warning there is no warning given and thus they ... suitable circumstances, trigger undefined behavior ... I have told you before how to avoid writing code ...
    (sci.crypt)
  • Re: C Test Incorrectly Uses printf() - Please Confirm
    ... Undefined behavior means the compiler is allowed to die screaming. ... nop or access to another register, the compiler is allowed to generate ... in an access to a pointer register that's in a state which causes a trap. ...
    (comp.lang.c)