Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
65 user(s) are online (60 user(s) are browsing Forums)

Members: 0
Guests: 65

more...

Support us!

Headlines

 
  Register To Post  

error: lvalue required as increment operand
Home away from home
Home away from home


See User information
@All
Tried to port some old 68k based code from GCC 2.x (strom) and have issues compiling some code, there are full test case:

#define ULONG unsigned int
#define UWORD unsigned short
#define UBYTE unsigned char


int main()
{    
    
UBYTE *chunkbuf;
    
UBYTE *chunky;
    
UBYTE *chunky2
    
UWORD val;   

    
val = *((UWORD*)chunkbuf)++;
    *((
UWORD*)chunky2)++ = val;
    *((
ULONG*)chunky2)++ = *((ULONG*)chunkbuf)++;
    *((
UWORD*)chunky2)++ = *((UWORD*)chunkbuf)++;
}


Don't take into account that things not initialized, etc, i just made a test case to show the errors i got in the "Right" code, with which i need to deal.

Currently i replace things like this:

val = *((UWORD*)chunkbuf)++; 
on
val 
= (*(UWORD *)&chunkbuf)++; 
 
 
*((
UWORD*)chunky2)++ = val
on
*(*(UWORD **)&chunky2)++ = val
 
 
*((
ULONG*)chunky2)++ = *((ULONG*)chunkbuf)++; 
on
*(*(ULONG **)&chunky2)++ = *(*(ULONG **)&chunkbuf)++;


Compiling errors gone, but i not sure if this is correct ones, because i have bugs and crashes.

Can anyone show the correct way of replacing those 4 strings so it will works as expected while compiles on modern gccs ?

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top
Re: error: lvalue required as increment operand
Not too shy to talk
Not too shy to talk


See User information
@kas1e
OMG, delete all you did
For simplicity you could go with a union like this:

union MixedPointer {
  
UBYTE *ubyte_ptr;
  
UWORD *uword_ptr;
  
ULONG *ulong_ptr;
};

int main()
{    
  
UBYTE *chunkbuf;
  
UBYTE *chunky;
  
UBYTE *chunky2
  
UWORD val;   

  
MixedPointer chunky2_mixed;
  
MixedPointer chunkbuf_mixed;
        
  
chunky2_mixed.ubyte_ptr=chunky2;
  
chunkbuf_mixed.ubyte_ptr=chunkbuf;

  
val=*chunkbuf_mixed.uword_ptr++;
  *
chunky2_mixed.uword_ptr++=val;
  *
chunky2_mixed.ulong_ptr++=*chunkbuf_mixed.ulong_ptr++;
  *
chunky2_mixed.uword_ptr++=*chunkbuf_mixed.uword_ptr++;
}


Untested TM

Go to top
Re: error: lvalue required as increment operand
Quite a regular
Quite a regular


See User information
Just taking the first example of
val=*((UWORD*)chunkbuf)++;


Is the intention just to grab whatever chunkbuf is pointing at and then increment chunkbuf to the next location?

val=*(UWORD*)(chunkbuf++);


This time, the lvalue is chunkbuf. Surely that is what the original intention was...

Not sure if the original intention was to increment the pointer as if it was a UWORD just before getting the value into val.

If liberty means anything at all, it means the right to tell people what they do not want to hear.
George Orwell.
Go to top
Re: error: lvalue required as increment operand
Not too shy to talk
Not too shy to talk


See User information
@rjd324
We cannot be 100% sure what the original purpose was as the code is illegal. Not just because of the casting/++ abuse but also because it guarantees misaligned data accesses which may be a problem depending on the target CPU.

Anyway, apparently the intention is to grab and store chunks of data of different types which are linearly tightly packed into some structure.
And because of lazyness the original coder tried to use the same UBYTE pointers for all different access variants.
It's of course dirty crap. However the old compiler obviously allowed to increase the pointers depending on the type they were casted to, so if it was casted to a temporary UWORD* the ++ operator would increase the original UBYTE* by sizeof(UWORD).

Your
val=*(UWORD*)(chunkbuf++);


has the same semantics as
val=*(UWORD*)(chunkbuf);
++
chunkbuf;


and defeats that purpose as it grabs a UWORD but then increases chunkbuf by sizeof(UBYTE) instead of sizeof(UWORD). So the next access would grab parts of the previously read value...
I strongly doubt that this was the original intention.

@kas1e
Of course my union solution doesn't fix potentially misaligned data access.

Go to top
Re: error: lvalue required as increment operand
Home away from home
Home away from home


See User information
@Daniel
Thanks for help as always !

It is some custom FLC player's code. And this is original routine to uncompress chunk into chunky pixels:

void decode_ss2 (UBYTE *chunkbufUBYTE *chunkystruct header *)
{
  
UWORD linespacketsbsize;
  
UBYTE *chunky2;
  
UWORD val;

  
lines = *chunkbuf++;
  
lines |= (*chunkbuf++ width 1) = (packets 0xff);
        }
    } while (
packets >= 32768);

    
chunky2 chunky;
    for ( ; 
packets 0; --packets) {
      
chunky2 += *chunkbuf++;
      
bsize = *chunkbuf++;
      if (
bsize 127)
      {
        
bsize 256 bsize;
        
val = *((UWORD*)chunkbuf)++;

        for ( ; 
bsize 0; --bsize)
            *((
UWORD*)chunky2)++ = val;
      }
      else
      {
            for( ; 
bsize 3bsize-=)
            {
                *((
ULONG*)chunky2)++ = *((ULONG*)chunkbuf)++;
                *((
ULONG*)chunky2)++ = *((ULONG*)chunkbuf)++;
            }

            for( ; 
bsize 0; --bsize )
                *((
UWORD*)chunky2)++ = *((UWORD*)chunkbuf)++;
      }
    }
    
chunky += s_bpr// was s_width
  
}
}


And decode_ss2 was called as "decode_ss2 (chunkbuf, chunky, &h ); (chunkbuf, chunky, &h ); " in the switch case for FLI_SS2, when we uncompress chunk into chunky pixels.


Edited by kas1e on 2022/5/4 8:14:26
Join us to improve dopus5!
AmigaOS4 on youtube
Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2024 The XOOPS Project