Topic: Static cast!  (Read 3719 times)

0 Members and 1 Guest are viewing this topic.

Toasty0

  • Guest
Static cast!
« on: February 12, 2003, 06:47:59 am »
I got your void* pointer right here pal...now, put down that static cast before I have to hurt you....bawahahaha  

NuclearWessels

  • Guest
Re: Static cast!
« Reply #1 on: February 12, 2003, 08:57:23 am »
LOL - late night debugging Toasty?

dave
 

Toasty0

  • Guest
Re: Static cast!
« Reply #2 on: February 12, 2003, 06:32:50 pm »
Yeah, I got home about 3am this morn and thought, "What the heck, I'll see what I can do about the void** to void* InterlockedCompareExchange compile time error that Ive been getting with VC++.Net2002." Even that long of a thought imeddiately brought on a headache...but that is another story.

After some research both through the help files and then on the MS site it seems that the action called for in the line of code: Code:
thisThreadOwnsTheOptex = (0 == ::InterlockedCompareExchange( (void**) &fSharedInfo.fLockCount,(void*) 1, 0) );


is absolutely forbidden within VC++.Net. Due to my not-so-thorough understanding of C++ it is a bit hazy why this is so, but it seems the pointer types are considered incompatable in C++ whereas they are not so in C.

Anyways, if I comprehend everything correctly, and I've been able to wrap my 45 year old brain around this file, it would seem that to correct this propblem would require re-coding some files not accessable to us through the scripting API.

Thus at this time I can only conclude that VC++.Net2002 as a scripting IDE is worhtless. Too bad for me because I was hoping to use it for scripting as my C++ and VC++ learning platform.

Oh well. STL/MFC/ATL anyone?

Best,
Jerry    

zaniwhoop2

  • Guest
Re: Static cast!
« Reply #3 on: February 12, 2003, 07:56:29 pm »
Have you tried dynamic_cast or reinterpret_cast? One of them might work (don't remember which). static_cast is like a 'safe' cast, if it doesn't work by the language, it won't let you do it, but one of the other ones I mentioned will let you do all sorts of dangerous stuff (the other one's for casting an inheritted object). If you want a void** to a void*, don't you just have to dereference the pointer?

Ex
void SomeFunction(void*);

void **pMyPtr;
SomeFunction(*pMyPtr);

Or is there a problems because it's a void type?  

Toasty0

  • Guest
Re: Static cast!
« Reply #4 on: February 13, 2003, 04:47:41 am »
Quote:

Have you tried dynamic_cast or reinterpret_cast? One of them might work (don't remember which). static_cast is like a 'safe' cast, if it doesn't work by the language, it won't let you do it, but one of the other ones I mentioned will let you do all sorts of dangerous stuff (the other one's for casting an inheritted object). If you want a void** to a void*, don't you just have to dereference the pointer?

Ex
void SomeFunction(void*);

void **pMyPtr;
SomeFunction(*pMyPtr);

Or is there a problems because it's a void type?  




I'm not sure. I'm sure not knowing is as much my lack of experience and knowledge as it is anything else.

It seems to be unhappy not with the fact that these are static per se, but rather with the fact that void** cannot be converted to a long pointer or some such. I guess that InterlockedCompareExchange examines to see if both pointers are of the same value (I assume zero in this case) and if they are equal then it replaces void** with void*. The problem is that VC++.Net says no way, chokes, sighs, and dies.

In another thread someone says they've simply removed the pointers and it compiles. I'm gonna give that a try, as I don't remember removing the whole function...but it would seem to me that doing so would cause a loss of thread control--which is what this optex file seems to be about to my untrained eye.

I suspect for now that the problem is the original initialization of the pointers. Of course, that supposition is worth squat coming from me.

Welp, time to do a bit more research to see what I can come up with.

Best,
Jerry