lvalue error needs explanation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Akhil

    lvalue error needs explanation

    plz c d following code

    #include<stdio. h>
    void main()
    {
    int x=4,y=1;

    y=x++++; //gives error message lvalue required

    y=x++ + ++y;//no errors

    y=x+++++y ;//lvalue required

    y=(++x)++; //no errors
    }

    explanation needed for the all four statements nd a bit bout lvalues.

    program tested on turbo 4.5 32 bit compiler.

  • Chris Dollin

    #2
    Re: lvalue error needs explanation

    Akhil wrote:
    [color=blue]
    > plz c d following code[/color]

    Syntax error: non-word "plz".
    Syntax error: unexpected initial "c".
    Syntax error: unexpected initial "d".
    Syntax error: imperative must end with "." or "!".
    Warning: April is the cruelest month.
    [color=blue]
    > #include<stdio. h>
    > void main()[/color]

    non-int `main`s produce undefined behaviour.
    [color=blue]
    > {
    > int x=4,y=1;
    >
    > y=x++++; //gives error message lvalue required[/color]

    An "lvalue" is (roughly) an addressable object, a variable.
    The left operand of ++ must be a lvalue. The result of ++
    is a number. Numbers are not lvalues. QED.
    [color=blue]
    > program tested on turbo 4.5 32 bit compiler.[/color]

    If it were a program, it would have compiled.

    --
    Chris "try, or try not -- there is no do" Dollin

    Comment

    • Akhil

      #3
      Re: lvalue error needs explanation

      thnx for d reply but i still hav a problem ....

      if we exeucte the statement y=(++x)++; then thr is no error ++x will
      again b a number nd left operand of ++ shud b a lvalue so y does it
      work in this case.

      Comment

      • Chris Dollin

        #4
        Re: lvalue error needs explanation

        Akhil wrote:
        [color=blue]
        > thnx for d reply but i still hav a problem ....[/color]

        Yes, you're still writing in gobbledegook. Please use English words
        and English grammar.
        [color=blue]
        > if we exeucte the statement y=(++x)++; then thr is no error[/color]

        Yes, there is - "invalid lvalue in increment" is how my local gcc reported
        it.
        [color=blue]
        > ++x will
        > again b a number nd left operand of ++ shud b a lvalue so y does it
        > work in this case.[/color]

        Broken compiler - /if/ it really did work.

        --
        Chris "try, or try not -- there is no do" Dollin

        Comment

        • CBFalconer

          #5
          Re: lvalue error needs explanation

          Akhil wrote:[color=blue]
          >
          > plz c d following code[/color]

          Gobble-de-gook is not understandable.
          [color=blue]
          >
          > #include<stdio. h>
          > void main()[/color]

          main returns int. All bets are off.
          [color=blue]
          > {
          > int x=4,y=1;
          >
          > y=x++++; //gives error message lvalue required[/color]

          Syntax errors normally do that.

          .... snip ...[color=blue]
          >
          > program tested on turbo 4.5 32 bit compiler.[/color]

          No non-compilable program is tested.

          --
          "If you want to post a followup via groups.google.c om, don't use
          the broken "Reply" link at the bottom of the article. Click on
          "show options" at the top of the article, then click on the
          "Reply" at the bottom of the article headers." - Keith Thompson
          More details at: <http://cfaj.freeshell. org/google/>
          Also see <http://www.safalra.com/special/googlegroupsrep ly/>


          Comment

          • Ian Collins

            #6
            Re: lvalue error needs explanation

            Akhil wrote:[color=blue]
            > plz c d following code
            >
            > #include<stdio. h>
            > void main()
            > {
            > int x=4,y=1;
            >
            > y=x++++; //gives error message lvalue required
            >[/color]
            You can't modify the result of x++, so it can't be an lvalue (something
            that appears on the left hand side of an expression).


            --
            Ian Collins.

            Comment

            • Ian Collins

              #7
              Re: lvalue error needs explanation

              Ian Collins wrote:[color=blue]
              > Akhil wrote:
              >[color=green]
              >> plz c d following code
              >>
              >> #include<stdio. h>
              >> void main()
              >> {
              >> int x=4,y=1;
              >>
              >> y=x++++; //gives error message lvalue required
              >>[/color]
              > You can't modify the result of x++, so it can't be an lvalue (something
              > that appears on the left hand side of an expression).
              >[/color]
              Sorry, that came out wrong, I should have said you can't modify the
              expression x++.



              --
              Ian Collins.

              Comment

              • Jordan Abel

                #8
                Re: lvalue error needs explanation

                On 2006-02-08, Akhil <akhilbhardwaj2 3@gmail.com> wrote:[color=blue]
                > plz c d following code
                >
                > #include<stdio. h>
                > void main()
                > {
                > int x=4,y=1;
                >
                > y=x++++; //gives error message lvalue required[/color]

                x++ returns a value, which you are then trying to increment
                [color=blue]
                > y=x++ + ++y;//no errors[/color]

                Except, of course, the undefined behavior
                [color=blue]
                > y=x+++++y ;//lvalue required[/color]

                this parses as x++ ++ +y
                [color=blue]
                > y=(++x)++; //no errors[/color]

                It _should_ be the same error as x++++ - i can't imagine why it's not.
                Have you actually tried this, or did your teacher just _say_ there are
                no errors?
                [color=blue]
                >}[/color]
                [color=blue]
                > explanation needed for the all four statements nd a bit bout lvalues.[/color]

                lvalues are, basically, expressions that it is legal to assign to /
                modify / increment - say, the name of a variable.
                [color=blue]
                > program tested on turbo 4.5 32 bit compiler.[/color]

                Comment

                • Jordan Abel

                  #9
                  Re: lvalue error needs explanation

                  On 2006-02-08, Akhil <akhilbhardwaj2 3@gmail.com> wrote:[color=blue]
                  > thnx for d reply but i still hav a problem ....
                  >
                  > if we exeucte the statement y=(++x)++; then thr is no error ++x will
                  > again b a number nd left operand of ++ shud b a lvalue so y does it
                  > work in this case.[/color]

                  Your compiler failed to provide a required diagnostic, and is thus not a
                  conforming ANSI C implementation.

                  Comment

                  • Vladimir S. Oka

                    #10
                    Re: lvalue error needs explanation

                    Jordan Abel wrote:[color=blue]
                    > On 2006-02-08, Akhil <akhilbhardwaj2 3@gmail.com> wrote:
                    >[color=green]
                    > > y=(++x)++; //no errors[/color]
                    >
                    > It _should_ be the same error as x++++ - i can't imagine why it's not.
                    > Have you actually tried this, or did your teacher just _say_ there are
                    > no errors?[/color]

                    It certainly produces the same `lvalue` error on GCC 3.4.2
                    (mingw-special) when compiled with paranoid options.
                    [color=blue][color=green]
                    > > program tested on turbo 4.5 32 bit compiler.[/color][/color]

                    Don't have this to test OP's results, but I have a strogn suspicion
                    that OP did not in fact try to compile this. If it does really compile
                    on TC 4.5, I'd complain to the vendor, but that won't work, as it's
                    discontinued.

                    --
                    BR, Vladimir

                    Comment

                    • Akhil

                      #11
                      Re: lvalue error needs explanation


                      Akhil wrote:[color=blue]
                      > plz c d following code
                      >
                      > #include<stdio. h>
                      > void main()
                      > {
                      > int x=4,y=1;
                      >
                      > y=x++++; //gives error message lvalue required
                      >
                      > y=x++ + ++y;//no errors
                      >
                      > y=x+++++y ;//lvalue required
                      >
                      > y=(++x)++; //no errors[/color]

                      i hav checked it on two compilers now the other one is DevC++ ,you can
                      find full specfication at
                      (http://csjava.occ.cccd.edu/~gilberts/devcpp5/) it certainly works in
                      both cases but might be because its primarily a c++ compiler anyways
                      please comment.
                      [color=blue]
                      > }[/color]

                      Comment

                      • Akhil

                        #12
                        Re: lvalue error needs explanation


                        sorry it was my fault actually i was compling the file with .cpp
                        extension so it was compiled as a c++ source code and hence no errors,i
                        got the error when i compiled the source code with .c extension,no more
                        questions

                        Comment

                        • Keith Thompson

                          #13
                          Re: lvalue error needs explanation

                          "Akhil" <akhilbhardwaj2 3@gmail.com> writes:[color=blue]
                          > sorry it was my fault actually i was compling the file with .cpp
                          > extension so it was compiled as a c++ source code and hence no errors,i
                          > got the error when i compiled the source code with .c extension,no more
                          > questions[/color]

                          Yes, C and C++ are different languages with different rules.

                          Thank you for dropping the silly abbreviations. You can help us even
                          more by using standard capitalization (the first word of each sentence
                          and the word "I"), and by following each comma with a blank.

                          I see you've read <http://cfaj.freeshell. org/google/>; please *always*
                          provide context when you post a followup, even if you're following up
                          to yourself.

                          --
                          Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
                          San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
                          We must do something. This is something. Therefore, we must do this.

                          Comment

                          • Christian Bau

                            #14
                            Re: lvalue error needs explanation

                            In article <1139388568.963 831.278110@o13g 2000cwo.googleg roups.com>,
                            "Akhil" <akhilbhardwaj2 3@gmail.com> wrote:
                            [color=blue]
                            > plz c d following code
                            >
                            > #include<stdio. h>
                            > void main()
                            > {
                            > int x=4,y=1;
                            >
                            > y=x++++; //gives error message lvalue required
                            >
                            > y=x++ + ++y;//no errors
                            >
                            > y=x+++++y ;//lvalue required
                            >
                            > y=(++x)++; //no errors
                            > }
                            >
                            > explanation needed for the all four statements nd a bit bout lvalues.
                            >
                            > program tested on turbo 4.5 32 bit compiler.[/color]

                            Just write down exactly what tokens the compiler sees; that will make it
                            obvious why spaces make a difference. A compiler is likely to give a
                            message "lvalue required" if an lvalue is required as an operand and the
                            operand you used is not an lvalue. So write down which operands are
                            lvalues and which are not.

                            For additional homework points: Spot the very serious error in "y=x++ +
                            ++y;" which you say has no error. Then tell us what the error is in
                            "y=(++x)++; " which you say has no error. Then tell us which is the very
                            first error in that program.

                            Comment

                            • Christian Bau

                              #15
                              Re: lvalue error needs explanation

                              In article <1139392127.339 786.100270@g47g 2000cwa.googleg roups.com>,
                              "Akhil" <akhilbhardwaj2 3@gmail.com> wrote:
                              [color=blue]
                              > thnx for d reply but i still hav a problem ....
                              >
                              > if we exeucte the statement y=(++x)++; then thr is no error ++x will
                              > again b a number nd left operand of ++ shud b a lvalue so y does it
                              > work in this case.
                              >[/color]

                              For heavens sake, use English.

                              Comment

                              Working...