Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Forced include file

Marcel_NLMarcel_NL Posts: 3Member
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

Comments

  • bilderbikkelbilderbikkel Posts: 754Member
    : 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



  • Marcel_NLMarcel_NL Posts: 3Member
    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
  • LundinLundin Posts: 3,711Member

    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.
  • Marcel_NLMarcel_NL Posts: 3Member
    :
    : 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.)
  • LundinLundin Posts: 3,711Member
    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?
Sign In or Register to comment.