precompiled header file

This is a discussion on precompiled header file within the C++ Programming forums, part of the General Programming Boards category; Hi Mats, To me stdafx.h and stdafx.cpp are both empty, can you post yours please? Originally Posted by matsp Not ...

  1. #16
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Hi Mats,


    To me stdafx.h and stdafx.cpp are both empty, can you post yours please?

    Quote Originally Posted by matsp View Post
    Not that I can see - but stdafx.pch is created when you compile stdafx.cpp, so if stdafx.cpp contains other include files, those will be part of stdafx.pch as I understand it - but that also means that if you turn off PCH, then the project won't compile, which is bad.

    --
    Mats

    regards,
    George

  2. #17
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,543
    Stdafx.h:

    Code:
    // stdafx.h : include file for standard system include files,
    // or project specific include files that are used frequently, but
    // are changed infrequently
    //
    
    #pragma once
    
    // Modify the following defines if you have to target a platform prior to the ones specified below.
    // Refer to MSDN for the latest info on corresponding values for different platforms.
    #ifndef WINVER				// Allow use of features specific to Windows XP or later.
    #define WINVER 0x0501		// Change this to the appropriate value to target other versions of Windows.
    #endif
    
    #ifndef _WIN32_WINNT		// Allow use of features specific to Windows XP or later.                   
    #define _WIN32_WINNT 0x0501	// Change this to the appropriate value to target other versions of Windows.
    #endif						
    
    #ifndef _WIN32_WINDOWS		// Allow use of features specific to Windows 98 or later.
    #define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later.
    #endif
    
    #ifndef _WIN32_IE			// Allow use of features specific to IE 6.0 or later.
    #define _WIN32_IE 0x0600	// Change this to the appropriate value to target other versions of IE.
    #endif
    
    #define _HAS_TR1 1
    
    #include <stdio.h>
    #include <tchar.h>
    #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS	// some CString constructors will be explicit
    
    #ifndef VC_EXTRALEAN
    #define VC_EXTRALEAN		// Exclude rarely-used stuff from Windows headers
    #endif
    
    #include <afx.h>
    #include <afxwin.h>         // MFC core and standard components
    #include <afxext.h>         // MFC extensions
    #ifndef _AFX_NO_OLE_SUPPORT
    #include <afxdtctl.h>		// MFC support for Internet Explorer 4 Common Controls
    #endif
    #ifndef _AFX_NO_AFXCMN_SUPPORT
    #include <afxcmn.h>			// MFC support for Windows Common Controls
    #endif // _AFX_NO_AFXCMN_SUPPORT
    
    #include <afxmt.h>
    #include <vector>
    #include <map>
    #include <fstream>
    #include <iostream>
    #include <cstdlib>
    #include <iomanip>
    #include <ctime>
    #include <cmath>
    #include <string>
    #include <list>
    #include <string>
    #include <new>
    //#include <stdint.h>
    #include <sstream>
    #include <Stuff\Requirements.h>
    
    // TODO: reference additional headers your program requires here
    Stdafx.cpp:
    Code:
    // stdafx.cpp : source file that includes just the standard includes
    // Help.pch will be the pre-compiled header
    // stdafx.obj will contain the pre-compiled type information
    
    #include "stdafx.h"
    
    // TODO: reference any additional headers you need in STDAFX.H
    // and not in this file
    Far from empty if you ask me.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #18
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by George2 View Post
    Hi Mats,


    To me stdafx.h and stdafx.cpp are both empty, can you post yours please?




    regards,
    George
    Considering I work with an embedded compiler that is NOT Microsoft compatible, the answer is no.

    In my hobby projects, I don't use precompiled headers for the very reason that I want to have all the includes needed for the project clearly visible in the C(++)-file, and not hidden inside some other file.

    If both stdafx.cpp and stdafx.h are empty, then precompiled headers make absolutely no sense at all.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #19
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks Mats,


    Quote Originally Posted by matsp View Post
    In my hobby projects, I don't use precompiled headers for the very reason that I want to have all the includes needed for the project clearly visible in the C(++)-file, and not hidden inside some other file.
    --
    Mats
    Why using pre-compiled header file will make code not convenient to read? I think even if we use /Yu in compile option, when reading code, the inlcude files are still in the source file, using /Yu or not only impact compiler's optimization, there is no code change in source file, why do you think using pre-compiled header file will make code not clear to read?


    Thanks Mats,


    "turn off" you mean turn off pre-compiled header creation (/Yc) or turn off pre-compiled header using (/Yu)?

    Quote Originally Posted by matsp View Post
    Not that I can see - but stdafx.pch is created when you compile stdafx.cpp, so if stdafx.cpp contains other include files, those will be part of stdafx.pch as I understand it - but that also means that if you turn off PCH, then the project won't compile, which is bad.

    --
    Mats

    Thanks Elysia,


    This conflicts with CornedBes's point in post #13, where he said the stdafx.h is empty. Any comments?

    (BTW: I did search for stdafx.h and stdafx.cpp in my VC folder, and some of them are empty and some of them are not.)

    Quote Originally Posted by Elysia View Post
    Stdafx.h:

    Code:
    // stdafx.h : include file for standard system include files,
    // or project specific include files that are used frequently, but
    // are changed infrequently
    //
    
    #pragma once
    
    ...
    Far from empty if you ask me.

    Thanks CornedBee,


    I think whether or not pre-compiled header is used is decided by the compiler option /Yu, why do you think it is decided by whether the related header file is empty or not -- "the compiler sees the include of the empty stdafx.h as a directive to use stdafx.pch"

    Quote Originally Posted by CornedBee View Post
    stdafx.h is empty. If PCH is disabled (no /Yu option), source.cpp will include the empty file and then attempt to use symbols from the headers included by stdafx.cpp. This will lead to compile errors.
    If PCH is enabled, the compiler sees the include of the empty stdafx.h as a directive to use stdafx.pch, which does include all those system headers.

    regards,
    George

  5. #20
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,543
    Quote Originally Posted by George2 View Post
    Thanks Elysia,

    This conflicts with CornedBes's point in post #13, where he said the stdafx.h is empty. Any comments?

    (BTW: I did search for stdafx.h and stdafx.cpp in my VC folder, and some of them are empty and some of them are not.)
    I'm a little fuzzy on the full details on how PCH works, so I don't know much about that,
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #21
    Registered User
    Join Date
    May 2006
    Posts
    1,579
    Thanks all the same, Elysia!


    Let us wait and learn from CornedBee and Mats. PCH is really fuzzy sometimes, and even you guru guys are sometimes having conflicting points. :-)

    Quote Originally Posted by Elysia View Post
    I'm a little fuzzy on the full details on how PCH works, so I don't know much about that,

    regards,
    George

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  2. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 07:51 PM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 12:13 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  5. Replies: 6
    Last Post: 04-02-2002, 04:46 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21