PDA

View Full Version : dereferencing void pointers


Duane
2005.05.04, 04:40 PM
i get an an error and a warning when I call 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?

kelvin
2005.05.04, 05:12 PM
cast it.
data[i] = ((Uint8*)surface->pixels)[i+2];

Duane
2005.05.04, 05:15 PM
thanks - It worked.
Now it stops building because of undefined symbols - even in the build log. it just says: Undefined Symbols:

Puzzler183
2005.05.04, 05:57 PM
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.

IBethune
2005.05.04, 06:01 PM
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

Duane
2005.05.04, 06:12 PM
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?

Puzzler183
2005.05.04, 06:14 PM
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.

Josh
2005.05.04, 06:17 PM
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.

Duane
2005.05.04, 06:24 PM
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.

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

Puzzler183
2005.05.04, 06:46 PM
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.

Duane
2005.05.04, 06:52 PM
Yes, it's C, but I am using the files with c++... I'll just compile it with a C program...

Puzzler183
2005.05.04, 07:25 PM
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.

Duane
2005.05.04, 07:41 PM
actually, no.
here are the files:
(.h (nayrsw.spymac.net/im.h)/.c (nayrsw.spymac.net/IM_tga.c))

Puzzler183
2005.05.04, 07:47 PM
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:


//vsprintf(file, filename, ap);
vsnprintf(file, sizeof(file), filename, ap);

Duane
2005.05.04, 07:50 PM
no. The symbol, i found out, is __TGASaveSurface.
Thanks for the tip, though!

Puzzler183
2005.05.04, 08:15 PM
Are you calling that from with your C++ file? If so, the prototype of the function (the predeclaration) must still be prefixed with extern "C".