C++ Builder

Moderators: Lundin
Number of threads: 509
Number of posts: 1146

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Forced include file Posted by Marcel_NL on 21 Jul 2008 at 2:57 AM
Hi,

Is there a way to define a forced include file in C++ Builder?
This file will then be included for each source file which will
be compiled, so it has the same effect as specifying

#include "forcedincludefile.h"

on the first line of every source file.

Many thanks,
Marcel

Report
Re: Forced include file Posted by bilderbikkel on 21 Jul 2008 at 4:06 AM
: Hi,
:
: Is there a way to define a forced include file in C++ Builder?
: This file will then be included for each source file which will
: be compiled, so it has the same effect as specifying
:
: #include "forcedincludefile.h"
:
: on the first line of every source file.
:
: Many thanks,
: Marcel
:
Hi Marcel,

Although I am an experienced user, I've never heard of this option.

There might be a complicated solution (on which I cannot help you) to this problem: instead of using the compiler directly, write an executable that adds first adds these lines to your header files, before calling the compiler.

Out of interest, I wonder why you would want this. If you want to work with precompiled headers, just create a header file called e.g. 'Precompile.h' that is called in every unit.

See ya, Bilderbikkel



Report
Re: Forced include file Posted by Marcel_NL on 21 Jul 2008 at 5:04 AM
Hi Bilderbikkel,

Thanks for your reply.

The reason I want to do this, is to be able to switch part of code on or off by defining preprocessor macros in the forced include file. I know these conditional defines can be defined in the project options, but I find it easier and much clearer when I can switch these defines on or off in the forced include file. Besides, when I use more than one compiler I only have to change the forced include file and not all compiler- or IDE-specific project settings. FYI: I am using the Borland compiler to build a PC-simulation of my app, while I am using another compiler for building the embbedded app. version.

My experiences are that more compilers, like the Microsoft C++ compiler and the IAR compiler I use for our embbedded platform, offer this option. But it seems, unfortunately, that Borland does not offer such an option

I could include the forced include file (also called preinclude file) in each source file myself, but I hoped (and still hope) there is an option to do this automatically....

Regards, Marcel
Report
Re: Forced include file Posted by Lundin on 21 Jul 2008 at 9:33 AM

It is always best to stick to ISO C, ie #include the header from every source file. That way you can port the code to MS or IAR.
Report
Re: Forced include file Posted by Marcel_NL on 22 Jul 2008 at 4:38 AM
:
: It is always best to stick to ISO C, ie #include the header from
: every source file. That way you can port the code to MS or IAR.

You are fully right. (But the danger here lies in forgetting to include the forced include file in new source code files (by e.g. new personnel) and thus not enabling any conditional code.)
Report
Re: Forced include file Posted by Lundin on 24 Jul 2008 at 12:21 PM
Well... if you are afraid of that, ain't too tricky to write a program that adds a line of code to every .h file in a directory, right?



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.