PDA

View Full Version : How do I use GetProcAddress()/wglGetProcAddress() without type cast?



Dravern
11-17-2002, 03:57 AM
Yes. I know I must cast returned value to right type, but I saw quake2 source code and found carmack doesn't cast type at all.

source code is something like this :
qglAccum = GetProcAddress(hModule, "glAccum");

How is this code compiled without an error?
Some compiler option?
I wanna know how.
Declare function type and cast to it for every single dll function.. so annoying.

Mezz
11-17-2002, 04:23 AM
It's because the files are compiled as C sources, which have less stringent type checking than if you compile them as C++ sources. There are still warnings however, but I guess he disables them with the line
#pragma warning (disable : 4113 4133 4047 )

-Mezz

Dravern
11-17-2002, 05:11 AM
Ah. I got it. Thanx.
So, Is there a compiler option (or some #pragma directive) that can alleviate the strictness of type checking as C compiler level?

OneSadCookie
11-17-2002, 10:29 AM
Why would you want to? More type-checking == good.

Dravern
11-17-2002, 12:10 PM
Just for dll functions I mentioned above and other similer case.
And Only if option could be turned on/off like #pragma warning.
If not, I'll cast. http://www.opengl.org/discussion_boards/ubb/smile.gif

MichaelK
11-18-2002, 02:46 AM
(void *&) qglAccum = GetProcAddress(hModule, "glAccum");

Assuming GetProcAddress is type void *

knackered
11-18-2002, 02:56 AM
lol! http://www.opengl.org/discussion_boards/ubb/smile.gif

MichaelK
11-18-2002, 03:15 AM
Originally posted by knackered:
lol! http://www.opengl.org/discussion_boards/ubb/smile.gif

Yes, I know http://www.opengl.org/discussion_boards/ubb/smile.gif

But, seriously, LOL has something with ROTFL? Am I right?

Dravern
11-18-2002, 07:20 PM
Originally posted by MichaelK:
(void *&) qglAccum = GetProcAddress(hModule, "glAccum");

Assuming GetProcAddress is type void *

It works! http://www.opengl.org/discussion_boards/ubb/eek.gif

Nakoruru
11-18-2002, 10:05 PM
One thing I have discovered is that programming is a lot easier if you just do what has to be done to make something work, and ignore things which are 'annoying'.

So what if you do not like type casts, if there is no other way then just do it and be annoyed by more important things ^_^

knackered
11-18-2002, 11:41 PM
Originally posted by MichaelK:
Yes, I know http://www.opengl.org/discussion_boards/ubb/smile.gif

But, seriously, LOL has something with ROTFL? Am I right?

Short of sampling myself laughing then emailing you the mp3, I use the common internet short hand for 'laugh-out-loud'. It's not something I like doing, using internet shorthand, but it's pretty difficult to express laughter in any other way.
Maybe I could pretend to be a narrator, and treat myself as the protagonist - something like:
"knackered chuckles warmly to himself at the reverse cast"

MichaelK
11-19-2002, 07:26 AM
Originally posted by knackered:
I use the common internet short hand for 'laugh-out-loud'.

Is this an idiom? How can you laugh out? Laugh out of what? Laugh out loud? Laugh out very loud? Load ah laud at?

All of this i know this is negative, right?

knackered
11-19-2002, 08:04 AM
It's an americanism.
This is not negative. Well, americanisms are negative, but this discussion is not, if you see what I mean.

V-man
11-20-2002, 06:27 AM
What happened to that other guy's library that does this ****. Lev?

I tried it last weak, but it wasn't up to date with 1.4

And I said, "What the ****! There must be some mistake here."

V-man