Welcome, Guest. Please login or register.

Author Topic: assignment problem with general pointers (VOID type )  (Read 1267 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2869
    • Show all replies
assignment problem with general pointers (VOID type )
« on: December 28, 2004, 07:01:04 PM »
Hey. I'm using jpeg.library and the pointer to the buffer I'm decompressing to is declared as APTR. Now the problem is that when I try to assign the value jpeg.library puts in it to another pointer VBCC complains sayint that it's an invalid type. If I try to cast it to the same type of pointer I'm copying it's value to, it complains saying that type VOID cannot be casted or something...
Maybe the easy way would be to copy it to some LONG first (haven't tryied it yet anyway...), but I wanted to know, is there a more elegant way around this?
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2869
    • Show all replies
Re: assignment problem with general pointers (VOID type )
« Reply #1 on: December 28, 2004, 07:08:16 PM »
By the way, the pointer I'm trying to copy the buffer pointer value to, was declared, if I remember correctly, something like:
Code: [Select]
struct Pixel
{BYTE Red;
 BYTE Green;
 BYTE Blue;
} *ImgPixelPosition;

 but I don't think this matters, it's just a pointer to a diferent type.

Hope the Pixel declaration doesn't coincide with some stuff on the Gfx library by the way, if I use it latter...
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2869
    • Show all replies
Re: assignment problem with general pointers (VOID type )
« Reply #2 on: December 30, 2004, 02:30:34 AM »
Bump.. :-(
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2869
    • Show all replies
Re: assignment problem with general pointers (VOID type )
« Reply #3 on: December 30, 2004, 07:13:26 PM »
@Trev

"So you're trying to assign a `APTR' (typedef void *APTR) to a `struct Pixel *'?"
Yes!

Thx for the tip. Not sure I uderstand the second part of the code (the C one).

func(&ptr); calls a function with an argument with a pointer to the ptr pointer correct? But for what?

pixel = (struct Pixel *)ptr;
This seems to be a normal cast.

Or did you mean:

func(&ptr);
void func(some type I don't know ptr, I guess void wouldn't work)
{pixel = (struct Pixel *)*ptr;
}

Ok, maybe this isn't what you mean.... :-D

Why da heck can't this be done easily in C :-o
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2869
    • Show all replies
Re: assignment problem with general pointers (VOID type )
« Reply #4 on: December 30, 2004, 07:21:03 PM »
Hey!!! Got one idea.
What about declaring Ptr as a Union with both types of pointers (struct Pixel * and APTR) ? :-D

By the way, since I'm an optimization freak, will the compiler make less efficient code like this, or will it simply remind the the Ptr variable can be both types. If I recall correctly the variable types in C are just like a list the compiler keeps to avoid the programmer making errors, shouldn't affect the code except for when a Union contains two or more types of diferent sizes, in this case the only difference would still be the size of the memory block reserved for the variable (being a size that could take the biggest type in the Union), but performance wise the code would be as fast right? :-D

I'm gonna try this when I get home, but some of you could say something about it... Maybe we're just all preparing to get drunk in the end of the year :-D
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2869
    • Show all replies
Re: assignment problem with general pointers (VOID type )
« Reply #5 on: January 07, 2005, 10:34:41 PM »
Hey, it just stroke me, that must also be why it's not permited to do pointer arithmetic with type void right ? Since the compiler doesn't know the size of the type the void * pointer points to it can't do pointer arithmetic.
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2869
    • Show all replies
Re: assignment problem with general pointers (VOID type )
« Reply #6 on: January 07, 2005, 10:57:09 PM »
Ups, hadn't read that part... :-)
\\"We made Amiga, they {bleep}ed it up\\"