#define TYPE_CHECK(T, S) \ while (false) { \ *(static_cast<T* volatile*>(0)) = static_cast<S*>(0); \ }
I am reading Google v8's code and found the above macro for type check.
However, I do not understand why it works. while(false) never get executed, right? Can someone explain those lines? Thanks
Code (short for source code) is a term used to describe text that is written using the protocol of a particular language by a computer programmer. Examples of programming languages include C, C#, C++, Java, Perl, and PHP.
Here's a simple example of code, written in the Python language: print 'Hello, world!' Many coding tutorials use that command as their very first example, because it's one of the simplest examples of code you can have – it 'prints' (displays) the text 'Hello, world! ' onto the screen.
Quite a fancy hack - the purpose of the macro seems to be to check if the type S
is assignable to (i.e., is a subclass of) the type T
. If it is not, the pointer cast from S*
to T*
will produce a compiler error. The while (false)
prevents the code from actually having any other effect.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With