Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Invalid lvalue...

This thread is locked; no one can reply to it. rss feed Print
Invalid lvalue...
jakerohs
Member #485
June 2000
avatar

I'm trying to get Allegro Sprite Editor to compile...using Allegro 4.2 (ASE is supposed to use 4.0.3). I've tried the pre-built executable but it disagrees with my 4.2 runtime. Anyways, that leaves me to do some tweaking in the ASE source to get it working. So far, so good, I've sorted out several trivial problems (such as ASE defining its own load_font function, even though Allegro has one with the same name) but I'm stuck on this error:

72: invalid lvalue in increment

unsigned char *address;
unsigned char value;

...
...
72: *(((unsigned short *)address)++) = value;

Pointer arithmetic is one of my weak areas - any idea what's wrong with line 72?

Alternatively, can anyone supply me with a compilable allegro 4.2 version of ASE? Or better still, a binary that works? :P

A J
Member #3,025
December 2002
avatar

((unsigned short *)address)++ huh?

your ++'ing an address ?

___________________________
The more you talk, the more AJ is right. - ML

GullRaDriel
Member #3,861
September 2003
avatar

And he is casting a u_char in a u_short before that.

"Code is like shit - it only smells if it is not yours"
Allegro Wiki, full of examples and articles !!

_Dante
Member #7,398
June 2006
avatar

Quote:

Pointer arithmetic is one of my weak areas

Then you really shouldn't be creating suspect constructions like this. There's so many things wrong with this statement, it's hard to know where to start.

Why are you casting a char to a short?
Why are you then assigning that casted value to another char?
And why, oh why, do people think that terse C code produces terse object code/assembly? Obfuscating your code does not make it smaller or faster, it just makes it obfuscated.

You need to stop for a moment and figure out what it is that you're really trying to accomplish. You should probably separate the pointer arithmetic from the assignment as well, or you'll be kicking yourself when you come back later and try to figure out what that line of code actually does, since it's clear that you barely understand it now.

-----------------------------
Anatidaephobia: The fear that somehow, somewhere, a duck is watching you

Steve++
Member #1,816
January 2002

You can't do that in one statement, because you can't apply pointer arithmetic of one type of pointer to another type of pointer, no matter how much you cast it. Try this:

*((unsigned short *)address) = value;
address += sizeof(unsigned short)/sizeof(unsigned char);

FMC
Member #4,431
March 2004
avatar

Quote:

Then you really shouldn't be creating suspect constructions like this. There's so many things wrong with this statement, it's hard to know where to start.

That code is from ASE, he didn't write it... ::)

[FMC Studios] - [Caries Field] - [Ctris] - [Pman] - [Chess for allegroites]
Written laws are like spiders' webs, and will, like them, only entangle and hold the poor and weak, while the rich and powerful will easily break through them. -Anacharsis
Twenty years from now you will be more disappointed by the things that you didn't do than by the ones you did do. So throw off the bowlines. Sail away from the safe harbor. Catch the trade winds in your sails. Explore. Dream. Discover. -Mark Twain

_Dante
Member #7,398
June 2006
avatar

Quote:

That code is from ASE, he didn't write it...

Yeah, my bad. I was kind of feeding into the two previous comments. Nonetheless, that line is a fabulous example of how not to write C code.

-----------------------------
Anatidaephobia: The fear that somehow, somewhere, a duck is watching you

spunit262
Member #5,545
February 2005
avatar

What is ASE ???

jakerohs
Member #485
June 2000
avatar

I agree, this is a prime example of how not to code. Nonetheless, this is in the ASE source code. I have no idea how the author got this stuff to compile, but anyhoo...

Quote:

What is ase?

Allegro Sprite Editor. I can't tell you any more about it since I haven't gotten it working yet.

It looks to me like the author is trying to move the pointer along 2 bytes (size of an unsigned short) instead of 1 byte (for a char). On most platforms.
I'll try substituting Steve++'s code and see how that goes.

Edit: Steve's code compiles fine (as it should). It just gets worse though - here's the next compilation error:

((unsigned char *)data->address) += data->image->w << data->shift;

Ewwwwww :P

Thanks for the help guys, but I give up. Allegro Sprite Editor is obviously someone's cruel joke, and I've fallen for it. You may all laugh at me now. ::)

miran
Member #2,407
June 2002

Quote:

I've tried the pre-built executable but it disagrees with my 4.2 runtime.

Then get yourself alleg40.dll.

Quote:

Allegro Sprite Editor is obviously someone's cruel joke, and I've fallen for it.

Well, if it hasn't been updated since Allegro 4.0.3 stopped being the last stable version of Allegro, then it's also probably dead.

--
sig used to be here

A J
Member #3,025
December 2002
avatar

jake, your avatar seems to be flipped.

___________________________
The more you talk, the more AJ is right. - ML

Go to: