gcc: What's illegal about this ?

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

    gcc: What's illegal about this ?

    I need a clue. I'm getting an "invalid lvalue in increment" from gcc
    4.1.2 on this line...

    sum += *((unsigned short *)iphp)++ ;

    ....but I don't see what the problem is. gcc 3.4.3 isn't bother by
    it, either.

    Machine specifics:

    $ uname -a
    Linux tmxnw-fc6 2.6.22.9-61.fc6 #1 SMP Thu Sep 27 18:48:03 EDT 2007
    i686 i686 i386 GNU/Linux

    $ gcc --version
    gcc (GCC) 4.1.2 20070626 (Red Hat 4.1.2-13)

  • Harald van =?UTF-8?b?RMSzaw==?=

    #2
    Re: gcc: What's illegal about this ?

    On Fri, 14 Mar 2008 17:49:16 +0000, Richard Eich wrote:
    I need a clue. I'm getting an "invalid lvalue in increment" from gcc
    4.1.2 on this line...
    >
    sum += *((unsigned short *)iphp)++ ;
    >
    ...but I don't see what the problem is. gcc 3.4.3 isn't bother by it,
    either.
    (unsigned short *)iphp is not an lvalue. Where do you want to store
    (unsigned short *)iphp + 1? Presumably, you want to store it in iphp. If
    you want that, write that.

    sum += *((unsigned short *)iphp);
    iphp = ((unsigned short *)iphp) + 1;

    You can consider it similar to
    int i;
    (i + 1) = -1;
    (double) i = 1.5;

    Comment

    • Ben Pfaff

      #3
      Re: gcc: What's illegal about this ?

      Richard Eich <richard.eich@d omain.invalidwr ites:
      I need a clue. I'm getting an "invalid lvalue in increment" from gcc
      4.1.2 on this line...
      >
      sum += *((unsigned short *)iphp)++ ;
      The part that GCC is complaining about is this:
      ((unsigned short *)iphp)++
      which attempts to increment the result of a cast. The result of
      a cast is never an lvalue, so you can't increment it. (GCC used
      to have an extension that permits this, but it was removed.)

      Perhaps you really mean:
      sum += (*((unsigned short *)iphp))++ ;
      --
      char a[]="\n .CJacehknorstu" ;int putchar(int);in t main(void){unsi gned long b[]
      ={0x67dffdff,0x 9aa9aa6a,0xa77f fda9,0x7da6aa6a ,0xa67f6aaa,0xa a9aa9f6,0x11f6} ,*p
      =b,i=24;for(;p+ =!*p;*p/=4)switch(0[p]&3)case 0:{return 0;for(p--;i--;i--)case+
      2:{i++;if(i)bre ak;else default:continu e;if(0)case 1:putchar(a[i&15]);break;}}}

      Comment

      • ymuntyan@gmail.com

        #4
        Re: gcc: What's illegal about this ?

        On Mar 14, 12:49 pm, Richard Eich <richard.e...@d omain.invalidwr ote:
        I need a clue. I'm getting an "invalid lvalue in increment" from gcc
        4.1.2 on this line...
        >
        sum += *((unsigned short *)iphp)++ ;
        >
        ...but I don't see what the problem is. gcc 3.4.3 isn't bother by
        it, either.
        Your code is invalid, result of a cast is not an lvalue
        (and hence not something you can apply ++ to). Quoting


        """
        The cast-as-lvalue extension has been removed for C++ and
        deprecated for C and Objective-C. In particular, code like this:
        int i;
        (char) i = 5;
        or this:
        char *p;
        ((int *) p)++;
        is no longer accepted for C++ and will not be accepted for C
        and Objective-C in a future version.
        """

        And "future version" was 4.something.

        Yevgen

        Comment

        • Aaron Hsu

          #5
          Re: gcc: What's illegal about this ?

          Richard Eich <richard.eich@d omain.invalidwr ites:
          >I need a clue. I'm getting an "invalid lvalue in increment" from gcc
          >4.1.2 on this line...
          > sum += *((unsigned short *)iphp)++ ;
          >...but I don't see what the problem is. gcc 3.4.3 isn't bother by
          >it, either.
          I think it would help if you could give us just a bit of context, at least.
          --
          Aaron Hsu <arcfide@sacrid eo.us| Jabber: arcfide@jabber. org
          ``Government is the great fiction through which everybody endeavors to
          live at the expense of everybody else.'' - Frederic Bastiat

          Comment

          • Richard Tobin

            #6
            Re: gcc: What's illegal about this ?

            In article <MPG.224484a711 0ac91798b037@ne ws.verizon.net> ,
            Richard Eich <richard.eich@d omain.invalidwr ote:
            >I need a clue. I'm getting an "invalid lvalue in increment" from gcc
            >4.1.2 on this line...
            >
            > sum += *((unsigned short *)iphp)++ ;
            >
            >...but I don't see what the problem is. gcc 3.4.3 isn't bother by
            >it, either.
            It's an extension in earlier versions of gcc, was accepted by
            some other C compilers before the ANSI standard, and was allowed in
            early drafts of the ANSI standard, but it not allowed now.

            -- Richard
            --
            :wq

            Comment

            • CBFalconer

              #7
              Re: gcc: What's illegal about this ?

              Aaron Hsu wrote:
              Richard Eich <richard.eich@d omain.invalidwr ites:
              >
              >I need a clue. I'm getting an "invalid lvalue in increment"
              >from gcc 4.1.2 on this line...
              >
              > sum += *((unsigned short *)iphp)++ ;
              >
              >...but I don't see what the problem is. gcc 3.4.3 isn't bother
              >by it, either.
              >
              I think it would help if you could give us just a bit of context,
              at least.
              In this case at least, why? That line of code is obviously wrong.
              Evem before the very queasy integer to pointer cast.

              --
              [mail]: Chuck F (cbfalconer at maineline dot net)
              [page]: <http://cbfalconer.home .att.net>
              Try the download section.



              --
              Posted via a free Usenet account from http://www.teranews.com

              Comment

              • ymuntyan@gmail.com

                #8
                Re: gcc: What's illegal about this ?

                On Mar 14, 4:48 pm, CBFalconer <cbfalco...@yah oo.comwrote:
                Aaron Hsu wrote:
                Richard Eich <richard.e...@d omain.invalidwr ites:
                >
                I need a clue. I'm getting an "invalid lvalue in increment"
                from gcc 4.1.2 on this line...
                >
                sum += *((unsigned short *)iphp)++ ;
                >
                ...but I don't see what the problem is. gcc 3.4.3 isn't bother
                by it, either.
                >
                I think it would help if you could give us just a bit of context,
                at least.
                >
                In this case at least, why? That line of code is obviously wrong.
                Evem before the very queasy integer to pointer cast.
                So context indeed would be helpful, because there is no
                integer to pointer cast ;)

                Yevgen

                Comment

                • Kenny McCormack

                  #9
                  Re: gcc: What's illegal about this ?

                  In article <frf1qq$1of2$1@ pc-news.cogsci.ed. ac.uk>,
                  Richard Tobin <richard@cogsci .ed.ac.ukwrote:
                  >In article <MPG.224484a711 0ac91798b037@ne ws.verizon.net> ,
                  >Richard Eich <richard.eich@d omain.invalidwr ote:
                  >>I need a clue. I'm getting an "invalid lvalue in increment" from gcc
                  >>4.1.2 on this line...
                  >>
                  >> sum += *((unsigned short *)iphp)++ ;
                  >>
                  >>...but I don't see what the problem is. gcc 3.4.3 isn't bother by
                  >>it, either.
                  >
                  >It's an extension in earlier versions of gcc, was accepted by
                  >some other C compilers before the ANSI standard, and was allowed in
                  >early drafts of the ANSI standard, but it not allowed now.
                  >
                  >-- Richard
                  >--
                  >:wq
                  What did it do?

                  As has been pointed out, it doesn't make any sense, so I'm having a hard
                  time imagining what it did in prior versions of gcc?

                  Comment

                  • Harald van =?UTF-8?b?RMSzaw==?=

                    #10
                    Re: gcc: What's illegal about this ?

                    On Sat, 15 Mar 2008 15:23:06 +0000, Kenny McCormack wrote:
                    In article <frf1qq$1of2$1@ pc-news.cogsci.ed. ac.uk>, Richard Tobin
                    <richard@cogsci .ed.ac.ukwrote:
                    >>In article <MPG.224484a711 0ac91798b037@ne ws.verizon.net> , Richard Eich
                    >><richard.eich @domain.invalid wrote:
                    >>>I need a clue. I'm getting an "invalid lvalue in increment" from gcc
                    >>>4.1.2 on this line...
                    >>>
                    >>> sum += *((unsigned short *)iphp)++ ;
                    >>>
                    >>>...but I don't see what the problem is. gcc 3.4.3 isn't bother by it,
                    >>>either.
                    >>
                    >>It's an extension in earlier versions of gcc, was accepted by some other
                    >>C compilers before the ANSI standard, and was allowed in early drafts of
                    >>the ANSI standard, but it not allowed now.
                    >
                    What did it do?
                    >
                    As has been pointed out, it doesn't make any sense, so I'm having a hard
                    time imagining what it did in prior versions of gcc?
                    In those versions, (ptrtype) ptrlvalue was treated in some (but not all)
                    contexts as *(ptrtype *) &ptrlvalue, except without aliasing problems (if
                    those versions understood aliasing at all).

                    Comment

                    • Richard Tobin

                      #11
                      Re: gcc: What's illegal about this ?

                      In article <e518f$47dbebd1 $541dfcd3$16772 @cache6.tilbu1. nb.home.nl>,
                      Harald van Dijk <truedfx@gmail. comwrote:
                      >As has been pointed out, it doesn't make any sense, so I'm having a hard
                      >time imagining what it did in prior versions of gcc?
                      >In those versions, (ptrtype) ptrlvalue was treated in some (but not all)
                      >contexts as *(ptrtype *) &ptrlvalue, except without aliasing problems (if
                      >those versions understood aliasing at all).
                      Though it's similar in effect to that expression, I would have hoped
                      it didn't rely on the pointer types having to the same representation,
                      which that does.

                      I would expect *(ptrtype *)ptrlvalue++ to be interpreted as
                      *(ptrtype *)ptrlvalue for the purpose of retrieving the value,
                      and as ptrlvalue = (type_of_ptrlva lue)(((ptrtype *)ptrlvalue) + 1)
                      for the side effect.

                      -- Richard
                      --
                      :wq

                      Comment

                      • Harald van =?UTF-8?b?RMSzaw==?=

                        #12
                        Re: gcc: What's illegal about this ?

                        On Sat, 15 Mar 2008 16:53:35 +0000, Richard Tobin wrote:
                        In article <e518f$47dbebd1 $541dfcd3$16772 @cache6.tilbu1. nb.home.nl>,
                        Harald van Dijk <truedfx@gmail. comwrote:
                        >>As has been pointed out, it doesn't make any sense, so I'm having a
                        >>hard time imagining what it did in prior versions of gcc?
                        >
                        >>In those versions, (ptrtype) ptrlvalue was treated in some (but not all)
                        >>contexts as *(ptrtype *) &ptrlvalue, except without aliasing problems
                        >>(if those versions understood aliasing at all).
                        >
                        Though it's similar in effect to that expression, I would have hoped it
                        didn't rely on the pointer types having to the same representation,
                        which that does.
                        Correct. I don't believe gcc has been ported to systems where different
                        pointer types have different representations (though I would be pleased
                        if proved wrong on this).

                        Comment

                        • CBFalconer

                          #13
                          Re: gcc: What's illegal about this ?

                          ymuntyan@gmail. com wrote:
                          CBFalconer <cbfalco...@yah oo.comwrote:
                          >Aaron Hsu wrote:
                          >>Richard Eich <richard.e...@d omain.invalidwr ites:
                          >>
                          >>>I need a clue. I'm getting an "invalid lvalue in increment"
                          >>>from gcc 4.1.2 on this line...
                          >>>>
                          >>> sum += *((unsigned short *)iphp)++ ;
                          >>>>
                          >>>...but I don't see what the problem is. gcc 3.4.3 isn't bother
                          >>>by it, either.
                          >>>
                          >>I think it would help if you could give us just a bit of context,
                          >>at least.
                          >>
                          >In this case at least, why? That line of code is obviously wrong.
                          >Evem before the very queasy integer to pointer cast.
                          >
                          So context indeed would be helpful, because there is no
                          integer to pointer cast ;)
                          iphp is cast to a pointer. Besides which the ++ operates on the
                          cast value, which is illegal. If iphp isn't integral things are
                          even worse.

                          --
                          [mail]: Chuck F (cbfalconer at maineline dot net)
                          [page]: <http://cbfalconer.home .att.net>
                          Try the download section.



                          --
                          Posted via a free Usenet account from http://www.teranews.com

                          Comment

                          • ymuntyan@gmail.com

                            #14
                            Re: gcc: What's illegal about this ?

                            On Mar 15, 6:30 pm, CBFalconer <cbfalco...@yah oo.comwrote:
                            ymunt...@gmail. com wrote:
                            CBFalconer <cbfalco...@yah oo.comwrote:
                            Aaron Hsu wrote:
                            >Richard Eich <richard.e...@d omain.invalidwr ites:
                            >
                            >>I need a clue. I'm getting an "invalid lvalue in increment"
                            >>from gcc 4.1.2 on this line...
                            >
                            >> sum += *((unsigned short *)iphp)++ ;
                            >
                            >>...but I don't see what the problem is. gcc 3.4.3 isn't bother
                            >>by it, either.
                            >
                            >I think it would help if you could give us just a bit of context,
                            >at least.
                            >
                            In this case at least, why? That line of code is obviously wrong.
                            Evem before the very queasy integer to pointer cast.
                            >
                            So context indeed would be helpful, because there is no
                            integer to pointer cast ;)
                            >
                            iphp is cast to a pointer.
                            It is, but it's a pointer from the very beginning.

                            char *iphp; // guessed
                            sum += *((unsigned short *)iphp)++ ;
                            Besides which the ++ operates on the
                            cast value, which is illegal.
                            Yep.
                            If iphp isn't integral things are
                            even worse.
                            Not really.

                            Yevgen

                            Comment

                            • CBFalconer

                              #15
                              Re: gcc: What's illegal about this ?

                              ymuntyan@gmail. com wrote:
                              CBFalconer <cbfalco...@yah oo.comwrote:
                              >ymunt...@gmail .com wrote:
                              >>CBFalconer <cbfalco...@yah oo.comwrote:
                              >>>Aaron Hsu wrote:
                              >>>>Richard Eich <richard.e...@d omain.invalidwr ites:
                              >>>>>
                              >>>>>I need a clue. I'm getting an "invalid lvalue in increment"
                              >>>>>from gcc 4.1.2 on this line...
                              >>>>>>
                              >>>>> sum += *((unsigned short *)iphp)++ ;
                              >>>>>>
                              >>>>>...but I don't see what the problem is. gcc 3.4.3 isn't
                              >>>>>bother by it, either.
                              >>>>>
                              >>>>I think it would help if you could give us just a bit of
                              >>>>context, at least.
                              >>>>
                              >>>In this case at least, why? That line of code is obviously
                              >>>wrong. Evem before the very queasy integer to pointer cast.
                              >>>
                              >>So context indeed would be helpful, because there is no
                              >>integer to pointer cast ;)
                              >>
                              >iphp is cast to a pointer.
                              >
                              It is, but it's a pointer from the very beginning.
                              So what? The only conversion available is to a void*, and from a
                              void* back to the original form. All others are illegal.
                              >
                              char *iphp; // guessed
                              sum += *((unsigned short *)iphp)++ ;
                              >
                              >Besides which the ++ operates on the cast value, which is illegal.
                              >
                              Yep.
                              >
                              >If iphp isn't integral things are even worse.
                              >
                              Not really.
                              Yes, really. Read the C standard.

                              --
                              [mail]: Chuck F (cbfalconer at maineline dot net)
                              [page]: <http://cbfalconer.home .att.net>
                              Try the download section.



                              --
                              Posted via a free Usenet account from http://www.teranews.com

                              Comment

                              Working...