Jump to content
  • Advertisement
Sign in to follow this  
Coro

What does this algorithm do?

This topic is 2124 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey everyone

I was looking at a game engine to see how the different developers structure the code in their projects. I came across this algorithm but cannot figure out what it does exactly.

This algorithm is stored in a header file.

// Static compile-time assertion
[color=#0000ff]namespace StaticAssert
{
[color=#0000ff]template< [color=#0000ff]bool > [color=#0000ff]struct FAILED;
[color=#0000ff]template<> [color=#0000ff]struct FAILED< [color=#0000ff]true > { };
}

[color=#0000ff]#define ASSERT_STATIC( exp ) (StaticAssert::FAILED< (exp) != 0 >())


Can anyone explain what it does? "ASSERT_STATIC" is implemented in a cpp file. Here's the code:

// Check some platform-dependent assumptions
// Note: this function is never called but just wraps the compile time asserts
[color=#0000ff]static void __ValidatePlatform__()
{
ASSERT_STATIC([color=#0000ff] sizeof( int64 ) == 8 );
ASSERT_STATIC( [color=#0000ff]sizeof( [color=#0000ff]int ) == 4 );
ASSERT_STATIC( [color=#0000ff]sizeof( [color=#0000ff]short ) == 2 );
ASSERT_STATIC( [color=#0000ff]sizeof( [color=#0000ff]char ) == 1 );
}


Thank you for reading!

Share this post


Link to post
Share on other sites
Advertisement
Thank you so much. You've explained that perfectly, I had a good Idea about what was going on but you explained the bits I couldn't figure out!

Share this post


Link to post
Share on other sites
For the record, it's a non-standard implementation of what the [font=courier new,courier,monospace]static_assert[/font] that's a part of the C++ language does, only with emitting the useful diagnostic message.

Share this post


Link to post
Share on other sites

For the record, it's a non-standard implementation of what the [font=courier new,courier,monospace]static_assert[/font] that's a part of the C++11 language does, only omitting the useful diagnostic message.
FTFY. A lot of game platforms don't support C++11 yet, so it's common to emulate these features via C++03 code.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!