473,569 Members | 2,764 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Precompiled headers on C

Is it possible to avoid using precompiled headers on files that don't
#include "stdafx.h".
I have an ATL project,which has got a lot of ATL #includes in its stdafx.h.
I now need to add some .c files to this project, that compile as hard raw
C - not C++.
The .c files obviously won't understand the <atlbase.h> etc that are in the
stdafx.h.
But if I leave the precompiled headers switch on, it complains that fatal
end of file was found looking for precompiled header directive, obviously in
the .c files. I though precompiled headers were just so that when it *did*
get included, it knew that if the .obj file was newer than the .h file, it
didn't have to recompile it.... is this not so?
I was going to put the .c files in a static library project, but it turns
out that it's more messy that way as the purpose of the .c files is to
access resource data.
Any ideas?
Nov 17 '05 #1
20 1616
"Bonj" <benjtaylor at hotpop d0t com> wrote in message
news:u7******** ******@TK2MSFTN GP10.phx.gbl...
Is it possible to avoid using precompiled headers on files that don't
#include "stdafx.h".
I have an ATL project,which has got a lot of ATL #includes in its stdafx.h. I now need to add some .c files to this project, that compile as hard raw
C - not C++.
The .c files obviously won't understand the <atlbase.h> etc that are in the stdafx.h.


Right-click on the file in the Solution Explorer, then Properties. You'll
probably want to select 'All Configurations' followed by: C/C++>Precompiled
Headers>Create/Use Precompiled Header = Not Using Precompiled Headers.
--
Jeff Partch [VC++ MVP]
Nov 17 '05 #2
Yes I know, that's exactly what I have done. But it doesn't exactly take the
benefit of using the stdafx.h.
I was wondering if there was some way you could still use the advantage of
precompiled headers while using .c files.
"Jeff Partch [MVP]" <je***@mvps.org > wrote in message
news:uG******** ******@TK2MSFTN GP12.phx.gbl...
"Bonj" <benjtaylor at hotpop d0t com> wrote in message
news:u7******** ******@TK2MSFTN GP10.phx.gbl...
Is it possible to avoid using precompiled headers on files that don't
#include "stdafx.h".
I have an ATL project,which has got a lot of ATL #includes in its

stdafx.h.
I now need to add some .c files to this project, that compile as hard raw
C - not C++.
The .c files obviously won't understand the <atlbase.h> etc that are in

the
stdafx.h.


Right-click on the file in the Solution Explorer, then Properties. You'll
probably want to select 'All Configurations' followed by:
C/C++>Precompiled
Headers>Create/Use Precompiled Header = Not Using Precompiled Headers.
--
Jeff Partch [VC++ MVP]

Nov 17 '05 #3
"Bonj" <benjtaylor at hotpop d0t com> wrote in message news:%2******** *******@TK2MSFT NGP09.phx.gbl.. .
Yes I know, that's exactly what I have done. But it doesn't exactly take the benefit of using the stdafx.h.
I was wondering if there was some way you could still use the advantage of precompiled headers while using .c files.


There is. You can setup a build where several different
groupings of headers are precompiled, then use any one
precompilation for different sources as you see fit. To
see how that works, study the docs on compiler options
relating to precompilation.

I may be wrong about this, but getting it to happen with
the IDE's semi-brainless automatic build system could be
a difficult process. You would then be facing creation of
an alternative build process. Many such exist and many
have found them atractive for various reasons, generally
because they allow such flexibility.

For your situation, I expect you would be better off
getting your .c files to compile as C++. Usually, the
changes necessary to do that are all improvements.

--
--Larry Brasfield
email: do************* **********@hotm ail.com
Above views may belong only to me.
Nov 17 '05 #4
"Bonj" <benjtaylor at hotpop d0t com> wrote in message
news:%2******** *******@TK2MSFT NGP09.phx.gbl.. .
Yes I know, that's exactly what I have done. But it doesn't exactly take the benefit of using the stdafx.h.
I was wondering if there was some way you could still use the advantage of
precompiled headers while using .c files.


Oh, you can set one *.c file to create another *.pch for all your other *.c
files to use.
--
Jeff Partch [VC++ MVP]
Nov 17 '05 #5
> There is. You can setup a build where several different
groupings of headers are precompiled, then use any one
precompilation for different sources as you see fit. To
see how that works, study the docs on compiler options
relating to precompilation.
Mmmm... it usually gets its knickers in a twist whenever I try to modify the
build settings, normally.

I may be wrong about this, but getting it to happen with
the IDE's semi-brainless automatic build system could be
a difficult process. You would then be facing creation of
an alternative build process. Many such exist and many
have found them atractive for various reasons, generally
because they allow such flexibility.
I think it would be better if you could set different build settings for
different files, this would allow you to compile managed and unmanaged ones
separately (separate issue, but...), then you could be sure they were
compiling the way you want.

For your situation, I expect you would be better off
getting your .c files to compile as C++. Usually, the
changes necessary to do that are all improvements.


Nah, I wouldn't dream of doing that. I love my C files, I want to keep them
that way - and I won't be forcing them to compile as C++. I'd do it in
assembly language if I knew it, but I don't! I generally think C to be good
for memory and such functions as manipulating resources, whereas all the
high-level ATL stuff is taken care of by the C++ side. The C files are the
only ones that are going to be modifying the global memory of the
application (well, DLL) - all of the stuff in the C++ ones is localized in
the ATL -based classes. It doesn't use any heap either - all of the memory
is in a resource file loaded into global namespace.

Cheers
Nov 17 '05 #6
"Bonj" <benjtaylor at hotpop d0t com> wrote in message
news:%2******** *******@TK2MSFT NGP09.phx.gbl.. .
Yes I know, that's exactly what I have done. But it doesn't exactly take the benefit of using the stdafx.h.
I was wondering if there was some way you could still use the advantage of
precompiled headers while using .c files.


Could you hack up the stdafx.h into two sections separated by
#ifdef _cplusplus
...
#else
...
#endif

Norm

Nov 17 '05 #7
"Bonj" <benjtaylor at hotpop d0t com> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
[Brasfield once wrote:]
For your situation, I expect you would be better off
getting your .c files to compile as C++. Usually, the
changes necessary to do that are all improvements.
Nah, I wouldn't dream of doing that. I love my C files, I want to keep them that way - and I won't be forcing them to compile as
C++. I'd do it in assembly language if I knew it, but I don't! I generally think C to be good for memory and such functions as
manipulating resources, whereas all the high-level ATL stuff is taken care of by the C++ side. The C files are the only ones that
are going to be modifying the global memory of the application (well, DLL) - all of the stuff in the C++ ones is localized in the
ATL -based classes. It doesn't use any heap either - all of the memory is in a resource file loaded into global namespace.


You seem to suffer under the misapprehension that
you would have to change the nature of your C code
in order to compile it as C++. That is not what I was
suggesting. If your C files are already ANSI C (rather
than the ancient K&R C), then with just a little work,
and no changes to the way the code operates, they
can be made acceptable to the C++ compiler. This
means a little less sloppiness with respect to typing,
and a few casts to make explicit what was implicit
in the C version, but the sequence of assignments
and calls, the data structures, and the form of
expressions can remain as they were. You need
not add any classes, use namespaces, or emply
any other purely C++ features. This usage is
commonly known as "using C++ as a better C".
(Of course, some C diehards quibble with this!)
Cheers


OK.

--
--Larry Brasfield
email: do************* **********@hotm ail.com
Above views may belong only to me.
Nov 17 '05 #8
"Norm Dresner" <nd***@att.ne t> wrote in message
news:nD******** ******@bgtnsc05-news.ops.worldn et.att.net...
"Bonj" <benjtaylor at hotpop d0t com> wrote in message
news:%2******** *******@TK2MSFT NGP09.phx.gbl.. .
Yes I know, that's exactly what I have done. But it doesn't exactly take

the
benefit of using the stdafx.h.
I was wondering if there was some way you could still use the advantage of precompiled headers while using .c files.


Could you hack up the stdafx.h into two sections separated by
#ifdef _cplusplus
...
#else
...
#endif

Norm


I just looked at the M/S on-line documentation for precompiled headers and
found this statement
"Although you can use only one precompiled header (.pch) file per source
file, you can use multiple .pch files in a project"

Would this accomplish some of what you want?

Norm

Nov 17 '05 #9
You seem to suffer under the misapprehension that
you would have to change the nature of your C code
in order to compile it as C++.
No, I don't - I suffer the apprehension (mis~ or otherwise) that there would
be no advantage in performance in converting it to C. The way I see it, it
is the same compiler backend that is building my program, but in C, it is
doing simpler things when compiling and having to conform to a stricter set
of rules about what it can do than when doing C++.
I personally very much doubt that there is any way of using the C++-only
features or the way C++ compiles that C doesn't, in order to increase the
speed of the program. But if this is what you meant by "using C++ as a
better C", then please tell me what they are - because I don't know them!
What I mean is, when I compile C, it is an old language that has been around
since the seventies or something. But the compiler I'm using hasn't been
around since the seventies, so the only advantages in using C++ would be in
what functionality I could use, not performance.
My C files would be acceptable to the C++ compiler, apart from the 'extern
"C" ...' bit. But without the precompiled headers, they're acceptable to the
C compiler aswell. It's like in a web application, if you're not using the
session state, you might aswell turn it off.
That is not what I was
suggesting. If your C files are already ANSI C (rather
than the ancient K&R C),
Oh god yes, they're standard, modern C. They compile with the MS 7.1
compiler just like the C++ files do, it's just they've got a .c extension.
No ancient compilers that use weird specifics or anything.
then with just a little work,
and no changes to the way the code operates, they
can be made acceptable to the C++ compiler. This
means a little less sloppiness with respect to typing,
and a few casts to make explicit what was implicit
in the C version,
I never do implicit casts anyway. I always use, for instance:
HMODULE hMod = (HMODULE)hInsta nce
I'm presuming this is faster than the static_cast<typ e> thingy or other?
but the sequence of assignments
and calls, the data structures, and the form of
expressions can remain as they were. You need
not add any classes, use namespaces, or emply
any other purely C++ features. This usage is
commonly known as "using C++ as a better C".
(Of course, some C diehards quibble with this!)
Cheers


OK.

--
--Larry Brasfield
email: do************* **********@hotm ail.com
Above views may belong only to me.

Nov 17 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2179
by: Asfand Yar Qazi | last post by:
Hi, Now that GCC 3.4 has precompiled headers, I'm thinking I can stop using pimpls to speed up development time, as it may make life easier (declaring pimpls takes a long time...) What are the views of the experienced users of various C++ implementations? Do precompiled headers allow pimpls to be avoided while maintaining the same speed...
2
2286
by: unspammable | last post by:
Several C++ compilers now allow precompiled headers, supposedly as a compile-time optimization. I personally do not use them, although I code mostly in VC++ (which has a tendency to shove PCH down your throat), because: a. When headers are lumped together into one huge entity the code loses a sense of who-uses-what, or so it seems to me. I...
1
3650
by: JoeS | last post by:
Is there anyway to share a single pch file between projects in VC 7.0? I have 300+ projects each of which creates its own pch. All projects include the exact same header files in the precompiled header. Its takes about 7 seconds to create the precompiled header for each project. That's 35 minutes spent creating precompiled headers for all...
1
1200
by: dt | last post by:
Having troubles with my program and i believe it has something to do with my project settings for precompiled headers. This is what i have: my main cpp file, vector.h/cpp and polygon.h/cpp. vector.h includes math, polygon includes vector and gl/gl.h, and main includes windows.h, gl/gl.h, gl/glu.h, gl/glaux.h and polygon.h i've tried...
0
1186
by: citizenkahn | last post by:
I read an article entitled "Sharing precompiled headers between projects" on this group. I am in the same situation as the requesting author, but the solution has not worked for me. Here is my situation, if anyone has a clue as to how I can solve this, please let me know. I am using VS.NET 2003 Arch. I have a solution two projects, a...
1
1367
by: Alvo von Cossel I | last post by:
yo, i have a simple hello world win32 console application. it should work but there is an error. here is the most important part of the error: have you forgotten to add #include <stdfx.h> to your source code? stdfx.h is a precompiled header and i have deleted it but vc++ still asks me to include it. how do i change the precompiled...
3
1917
by: Kevin Frey | last post by:
I am working on a test migration of our project to Visual Studio 2005 Beta 2 as a precursor to the availability of the full release of VS2005. The most onerous problem so far concerns the requirement by LINK.EXE that if an object file has used precompiled headers, then the resulting "precompiled header object file" must also be one of the...
0
1932
by: simon.hudon | last post by:
Hi everyone, I have a strange problem with precompiled headers with VC8. I have the problem while trying to use a precompiled header to build another precompiled header. I tried the sample code provided on msdn for the use of /Yu /Yc and while it works well with VC++ 7.0, it doesn't with VC++ 8.0...
8
1467
by: Abubakar | last post by:
Hi, I am writing some unmanaged c++ code that would need to be compiled in the future using compilers other than vc++. I'm using the feature of vc++ "use precompiled headers", is there going to be any problem if I compile this code on other compilers? I'm asking this because when I use pch *some* of my cpp files has following as there first...
0
7609
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7921
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7666
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7964
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6278
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5504
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1208
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.