Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1064127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T18:53:05+00:00 2026-05-16T18:53:05+00:00

While reviewing Visual C++ codebase I found a following strange thing. A run-time assert

  • 0

While reviewing Visual C++ codebase I found a following strange thing. A run-time assert (which is check the condition and throw an exception if the condition is violated) was used in a case when the condition could be evaluated at compile time:

assert( sizeof( SomeType ) == sizeof( SomeOtherType ) );

clearly the compiler will evaluate the condition and replace the code that will effectively be either

assert( true );

which does nothing or

assert( false );

which throws an exception every time control passes through that line.

IMO a compile-time assert should have be used instead for the following reasons:

  • it would expose the condition violation earlier – at compile time – and
  • it would let cleaner (thus faster and smaller) machine code be emitted

Looks like a compile-time assert is the only right thing. Is there any possible reason to prefer a run-time assert here?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T18:53:06+00:00Added an answer on May 16, 2026 at 6:53 pm

    There’s no reason to prefer a run-time assert here. You should prefer compile-time errors over run-time errors so there’s never a reason, given the option between the two, to choose a run-time assert.

    However, if a static assert isn’t an option (doesn’t know the concept of a static assert, doesn’t know how to make one and doesn’t have one available, or knows how to make one but doesn’t have the time to), a run-time assert is the next best thing.

    With C++0x, the built-in static_assert feature should end all reason to use a run-time assert where a compile-time assert would work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While reviewing some PHP code I've discovered a strange thing. Here is the simple
While playing with standard library i've found a strange difference between python2 and python3.
Reviewing a quite old project I found the following curious code snippet (only relevant
While renewing iOS Developer program I have found Apple generated some Company ID instead
While deveoping a site (using Forms authentication and InProc sessionstate) a frequently run into
while looking at some code I stumbled onto: throw /*-->*/new std::exception (//... and I
I am finishing a course on design patterns, and while reviewing the notes came
Had the following as an interview question a while ago and choked so bad
I'm reviewing some legacy code and I've found a bug that causes the response
I am using twitter bootstrap in a project and while reviewing the documentation, i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.