Is f() lvalue?

From: Michael Ovetsky (movetsky_at_ureach.com)
Date: 10/31/04


Date: Sun, 31 Oct 2004 14:29:14 +0000 (UTC)


Consider:

int g(){int b=1; return b;}

int main()
{
        int d=2;
        g()=d;
}

gcc compiler fails to compile it with 'non-lvalue in assignment' error
message, which I would expect.

However the following code happily compiles and executes:

struct A {int a;};
A f(){A b={1}; return b;}

int main()
{
        A c ={2};
        f()=c;
}

Does it mean that f() is lvalue if f returns struct or class object, but
  not lvalue if f returns built-in type or incorrect implementation of
C++ standard by gcc is one to blame?

Thanks,

Michael

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated. First time posters: Do this! ]

[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]



Relevant Pages

  • Re: It Pays to Enrich Your C Skills
    ... Check if you can score a perfect 10 (without using a compiler). ... int main{ ... struct bitfield { ... out if it is a negative integer constant or a constant expression ...
    (comp.lang.c.moderated)
  • OT: Re: Perl Peeves
    ... I see the result of a test being used as an int. ... the compiler just assumed you knew what you were doing ... introduced to the language later, so void * was unheard of in most code. ... This didn't mean bool was special, declaring it just signaled to the ...
    (comp.lang.perl.misc)
  • Re: OT: Re: Perl Peeves
    ... when I see the result of a test being used as an int. ... compiler just assumed you knew what you were doing and would ... This didn't mean bool was special, declaring it just signaled to the ... What "normalization of bool results is built into the compiler"? ...
    (comp.lang.perl.misc)
  • Re: [CodeGallery] MFC MD5 Calculator
    ... Then when they added types, internally, the compiler still thought they were int values, ... ANSI standard began to emerge that the language design ...
    (microsoft.public.vc.mfc)
  • Re: cpu type idea
    ... compiler related recently. ... int main ... float a; ... just to parallelize the vectror and tensor operations. ...
    (alt.lang.asm)