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

  • SEARCH
  • Home
  • 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 9224429
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:19:07+00:00 2026-06-18T04:19:07+00:00

Based on Mats Petersson’s results, I did some tests. My work on turning the

  • 0

Based on Mats Petersson’s results, I did some tests. My work on turning the assert on and off by defining a macro is not necessary. My conclusions are:

  1. Including standard headers such as <cassert>, <vector>, <memory> and so on, takes little compilation time. We don’t need to care.
  2. Be careful in including your own files. Include those that are really needed because the dependent requires recompilation after the change of the depended.
  3. Be careful when including collection headers of class library, such as <QWidgets> (Qt header to include all its widgets). This takes a huge time in compilation.

[Original Post]

Does it take long compilation time if every files includes “assert.h”? I think similar questions on “math.h” or other common files. I don’t like pre-compiled header. This happens when I have a Vector3D class which represents a vector in 3D space with x, y, z component. The class is used almost everywhere. I have a function named component(int i) where i is asserted between 0 and 2. For performance reason, I don’t put its implementation in cpp file. Thus “assert.h” is included almost everywhere.

#pragma once

#include <assert.h>

/// A vector in a 3D space with 3 components: x, y, and z.
class Vector3D
{
public:
    Vector3D(float x = 0, float y = 0, float z = 0)
    {
        m_component[0] = x;
        m_component[1] = y;
        m_component[2] = z;
    }

    float x() const    {return m_component[0];}
    float y() const    {return m_component[1];}
    float z() const    {return m_component[2];}

    void setX(float x)    {m_component[0] = x;}
    void setY(float y)    {m_component[1] = y;}
    void setZ(float z)    {m_component[2] = z;}

    float component(int i) const
    {
        assert(i >= 0 && i < 3);
        return m_component[i];
    }

    float& component(int i)
    {
        assert(i >= 0 && i < 3);
        return m_component[i];
    }

private:
    float m_component[3];
};

Inspired by Floris Velleman, I add a file to define my ASSERT to turn on and off it. It requires changing assert to ASSERT in the code using assert. Thanks.

#ifdef USE_ASSERT
# include <assert.h>
# define ASSERT(statement) assert(statement)
#else
# define ASSERT(statement)
#endif
  • 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-06-18T04:19:08+00:00Added an answer on June 18, 2026 at 4:19 am

    All headers use the same inclusion model, which is tremendously slow. Some headers may be more complex than others, but in general, you don’t include a header you don’t need.

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

Sidebar

Related Questions

Based on this article I was able to get the FullName to work rather
Based on command-line input, I need to set some run-time constants which a number
Based off information found in a couple of posts online ( http://www.magentocommerce.com/boards/viewthread/178767/ and http://marius-strajeru.blogspot.co.uk/2010/04/create-bulk-discount-rules.html
Based on the current uploadify documents, it uses formData (weird all google search results,
Based on the docs on akki.io I'm not seeing what common use cases the
Based on the bigquery query reference, currently Quantiles do not allow any kind of
Based on some data I'm cloning a div with a checkbox and check it
Based on some exceptionally helpful tips, I am using the following code to include
Based on some other code I found from this site (This Question here -
Based on my previous thread : RVM installed by Ruby not working? where 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.