dereferencing void pointers

Member
Posts: 567
Joined: 2004.07
Post: #1
i get an an error and a warning when I call
PHP Code:
data[i] = surface->pixels[i+2]; // where data is a Uint8 (unsigned char/byte) pointer and pixels is a void pointer 

error: void value not ignored as it ought to be


(warning): dereferencing `void *' pointer


What should I do?

It's not magic, it's Ruby.
Quote this message in a reply
Member
Posts: 469
Joined: 2002.10
Post: #2
cast it.
Code:
data[i] = ((Uint8*)surface->pixels)[i+2];

---Kelvin--
15.4" MacBook Pro revA
1.83GHz/2GB/250GB
Quote this message in a reply
Member
Posts: 567
Joined: 2004.07
Post: #3
thanks - It worked.
Now it stops building because of undefined symbols - even in the build log. it just says: Undefined Symbols:

It's not magic, it's Ruby.
Quote this message in a reply
Puzzler183
Unregistered
 
Post: #4
Try a clean rebuild (as in, delete the object files). And then try changing it back and seeing if it actually worked before your change or if it was a fluke.
Quote this message in a reply
Member
Posts: 156
Joined: 2002.10
Post: #5
The undefined symbols error is probably unrelated and due to a change you've made elsewhere. To see which symbol is undefined just drag open the bottom panel in the build results window - you can get this by clicking on the little dot in the centre of the bottom bar (this is actually a divider which is pulled right down by default).

Have a look at which symbol is undefined - if it's your own, then you've probably forgotten to implement some function or other, otherwise you've messed up linking to some external libraries.

- Iain
Quote this message in a reply
Member
Posts: 567
Joined: 2004.07
Post: #6
No, that's what I meant by the build log- it doesn't say. I will try a clean rebuild, though. MAybe the symbol was a space or something?

It's not magic, it's Ruby.
Quote this message in a reply
Puzzler183
Unregistered
 
Post: #7
AFAIK, symbols can't be whitespace... Was there an underscore or anything?

And I forgot to warn you in your last post: what you are doing probably isn't cross platform compatible, maybe even to linux or Windows because of endian issues... And of course to other platforms for entirely different issues.
Quote this message in a reply
Moderator
Posts: 608
Joined: 2002.04
Post: #8
Quote:No, that's what I meant by the build log- it doesn't say. I will try a clean rebuild, though. MAybe the symbol was a space or something?
No, really, there is more to the log. For whatever reason, the "pretty" error reporter never shows the symbols. You must drag the seperator and then look at the raw log to see what the undefined symbols were.
Quote this message in a reply
Member
Posts: 567
Joined: 2004.07
Post: #9
Josh Wrote:No, really, there is more to the log. For whatever reason, the "pretty" error reporter never shows the symbols. You must drag the seperator and then look at the raw log to see what the undefined symbols were.
I know.

It is a linker error, though, When I drag the error to text, it gives: "ld: Undefined Symbols:" then a newline.

[edit]OK, I think the error is the function itself. The source file (*.c) is named differently then the header file. Will look into this.[/edit]

It's not magic, it's Ruby.
Quote this message in a reply
Puzzler183
Unregistered
 
Post: #10
That shouldn't make a difference. Although, it's a .c file? So you are writing C, not C++ right? Because that definitely makes a difference also.
Quote this message in a reply
Member
Posts: 567
Joined: 2004.07
Post: #11
Yes, it's C, but I am using the files with c++... I'll just compile it with a C program...

It's not magic, it's Ruby.
Quote this message in a reply
Puzzler183
Unregistered
 
Post: #12
Ok, on C++ functions the symbols are mangled names, not the actual names. So, are you calling any C++ functions in your C program? If so, you need to prefix them with extern "C" so that they will have the right naming.
Quote this message in a reply
Member
Posts: 567
Joined: 2004.07
Post: #13
actually, no.
here are the files:
(.h/.c)

It's not magic, it's Ruby.
Quote this message in a reply
Puzzler183
Unregistered
 
Post: #14
Well it could be caused in another place too. Try reducing your project to the minimal amount needed to reproduce the error.

And btw, you are vulernable to a buffer overflow because of your vsprintf. Try replacing it with this:

Code:
//vsprintf(file, filename, ap);
    vsnprintf(file, sizeof(file), filename, ap);
Quote this message in a reply
Member
Posts: 567
Joined: 2004.07
Post: #15
no. The symbol, i found out, is __TGASaveSurface.
Thanks for the tip, though!

It's not magic, it's Ruby.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  c pointers and memory allocation NelsonMandella 15 7,400 Feb 27, 2010 12:59 AM
Last Post: Kerome
  C++ pointers (multiple uses inside a class) problems :( wyrmmage 14 5,897 Jun 2, 2007 10:08 AM
Last Post: akb825
  Help with converting from void to int. qoo111 5 3,095 Apr 18, 2007 05:41 AM
Last Post: ThemsAllTook
  trouble with structure pointers ferum 2 2,878 Mar 24, 2006 05:57 PM
Last Post: ferum
  Problems With Arrays of Pointers Nick 8 3,873 Sep 27, 2005 04:53 PM
Last Post: Zekaric