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 8212305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T10:42:36+00:00 2026-06-07T10:42:36+00:00

I ran into precompiled headers today for the first time..forever changing my life. I

  • 0

I ran into precompiled headers today for the first time..forever changing my life. I can’t believe compiling my C++ code could be that fast. It makes total sense now..

Anyway, one thing that is confusing me is that from what I’ve read so far, pre-compiled headers only should be added to source files( cpp? ).

In Visual Studio, there is an option under Project Properties->C/C++->Advanced to “Force Include File”. I set that compiler option to stdafx.h.

After doing this..I no longer require to include the headers I have added to my stdafx.h, even inside my header files ( source files are supposed to automatically include stdafx.h ). Is this expected behaviour?

I can’t find a place that’s clear in the distinction between header/source files.

If it does..great but I’m afraid it’s another one of those things VC++ lets you get away with but will break in GCC. And yes..it needs to be portable; at least between GCC and VC++.

  • 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-07T10:42:39+00:00Added an answer on June 7, 2026 at 10:42 am

    StdAfx.h really should only be included in source files, not headers. I would suggest you #include “StdAfx.h” first in every cpp and not use the “Force Include File” option. Thats how I do it with my cross-platform projects. For the record, I don’t actually use precompiled headers in GCC I just build it normally and it works well.

    For some background. The compiler only looks at source files (ie, *.cpp, *.c, etc) and so when it compiles them it has to include every header and compile any code found in the headers as well. The precompiled headers option allows for compiling all of that code (ie, the globally include’d code in StdAfx.h) once so that you don’t have to do it all of the time. Thats what StdAfx.cpp is for. The compiler compiles StdAfx.cpp with all of the code included in StdAfx.h once instead of having to do it every time you build.

    So, since you include StdAfx.h in every source file as the first item, it doesn’t make sense to include it in any of the headers since they will be included AFTER StdAfx.h and thus will have access to all of the code in StdAfx.h. Plus you can then use those headers in other projects without having to worry about having a StdAfx.h around or including the wrong one.

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

Sidebar

Related Questions

Ran into a strange problem in PHP today and I'm wondering if someone can
I ran into a bad chunk of code today that equates to this: [[asdf]].each
I ran into an issue today and I have been stumped for some time
I ran into a scenario where I had a delegate callback which could occur
I ran into a problem using java objects in jython today because jython is
I ran into a situation today where Java was not invoking the method I
I ran into such problem: I have one header file: //first variant: #ifndef LIBRARIES_H
Ran into a issue today. abc.ClassA a = (abc.ClassA) request.getsession().getAttribute(); and i get classcast
I ran into an issue. Below is my code, which asks user for input
I ran into an unexpected code optimization recently, and wanted to check whether my

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.