Function pointers

Hi

I am using SDL v1.2 in win98 with the MSVC++ v6.
The problem that I have is with functions pointers. All my source code is spread over into seperate files and I don’t know the rules about sending attachments.

I have a plot pixel function pointer and the plot pixel functions (256 colour, 16bit 32bit) and the function that assigns the pointer to the respective plot pixel function. These functions are sitting in a seperate file along with the function pointer.

Then the file which contains the main, ( which naturally will include the pixel_plot.h file ) will give me a linker error when I build. Basically it will give me lnk2005 and say that the pixel plot function pointer has been declared twice when it only has been declared once. I look at the help and it tells me that this problem is most of the time caused by linking multithreaded libraries with singel threaded ones and so on. I need help here, is it something todo with the settings? I can force the link and it works fine.–


Talk More, Pay Less with Net2Phone Direct®, up to 1500 minutes free!
http://www.net2phone.com/cgi-bin/link.cgi?143

I am using SDL v1.2 in win98 with the MSVC++ v6.
The problem that I have is with functions pointers. All my source code is
spread over into seperate files and I don’t know the rules about sending
attachments.

Then the file which contains the main, ( which naturally will include the
pixel_plot.h file ) will give me a linker error when I build. Basically it
will give me lnk2005 and say that the pixel plot function pointer has been
declared twice when it only has been declared once. I look at the help and
it tells me that this problem is most of the time caused by linking
multithreaded libraries with singel threaded ones and so on. I need help
here, is it something todo with the settings? I can force the link and it
works fine.

I use something like this in a 2D program.(is better if you uses
namespaces):

Draw.h

extern void (*drawpixel)(…);

void drawpixel8(…);
void drawpixel16(…);
void drawpixel24(…);--------------------------------
Draw.c

void (*drawpixel)(…)=drawpixel8;

void drawpixel8(…){…};
void drawpixel16(…){…};
void drawpixel24(…){…};


init.cpp

#include “draw.h”


switch(bpp){
case 1:
drawpixel=drawpixel8; break;
case 2:
drawpixel=drawpixel8; break;
case 3:
drawpixel=drawpixel8; break;
}

If you use pointers to class functions it have to be static or use friend
function. Or its my experience.


mensaje enviado desde http://www.iespana.es
emails (pop)-paginas web (espacio illimitado)-agenda-favoris (bookmarks)-foros

In file1.c:

extern void foo(void);

void (*fooptr)() = foo;

In file2.c:

void foo(void)
{
doSomethingInvolving(FOO);
}

That should compile and link.

Remember:
-Functions defined in other files should be marked extern
-Symbols referenced in other files must not be marked static, or the
linker won’t export them

-JohnOn Sunday, September 2, 2001, at 10:44 PM, fat cat wrote:

Hi

I am using SDL v1.2 in win98 with the MSVC++ v6.
The problem that I have is with functions pointers. All my source code is
spread over into seperate files and I don’t know the rules about sending
attachments.

I have a plot pixel function pointer and the plot pixel functions (256
colour, 16bit 32bit) and the function that assigns the pointer to the
respective plot pixel function. These functions are sitting in a seperate
file along with the function pointer.

Then the file which contains the main, ( which naturally will include the
pixel_plot.h file ) will give me a linker error when I build. Basically
it will give me lnk2005 and say that the pixel plot function pointer has
been declared twice when it only has been declared once. I look at the
help and it tells me that this problem is most of the time caused by
linking multithreaded libraries with singel threaded ones and so on. I
need help here, is it something todo with the settings? I can force the
link and it works fine.


Talk More, Pay Less with Net2Phone Direct®, up to 1500 minutes free!
http://www.net2phone.com/cgi-bin/link.cgi?143


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


John R. Hall | Overfull \brain has occurred while \learn is active
CS Student - Georgia Tech | Author - Programming Linux Games
Unsolicited commerical e-mail will be considered an act of war.

[…]

Remember:
-Functions defined in other files should be marked extern
-Symbols referenced in other files must not be marked static, or the
linker won’t export them

Also, although it may not apply to this particular project, remember that
C++ object files have mangled symbol names while C object files don’t.
Inside C++ files (or rather, in headers to be included from C++ files),
you need to use:

extern "C"
{
	<various extern stuff in C files>
}

//David Olofson — Programmer, Reologica Instruments AB

.- M A I A -------------------------------------------------.
| Multimedia Application Integration Architecture |
| A Free/Open Source Plugin API for Professional Multimedia |
----------------------------> http://www.linuxdj.com/maia -' .- David Olofson -------------------------------------------. | Audio Hacker - Open Source Advocate - Singer - Songwriter |--------------------------------------> david at linuxdj.com -'On Monday 03 September 2001 18:35, John R. Hall wrote: