473,388 Members | 1,286 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Preference: Header File OR Compile Flags?

Hello all:

I apologize if this query seems a bit off-topic. But I couldn't think
of another place to post my message.

I would like to get an idea of how you all like to handle preprocessor
defines. Do you like to create a header file with all the associated
defines and then include it with every frickin' source file that's
created/modified, OR do you appreciate the ability to pass these on
the command line or from a makefile? Can you tell which method I
prefer?

I have been involved with some discussions on this topic, and though I
have voiced my preference (along with a few reasons to support), I
don't feel like I'm coming up with compelling reason(s) for supporting
my preference. Is this just purely subjective and wreaking of someone
having too much time on their hands? Or is there some strong reasons
for choosing one method or the other?

Thanks, in advance,
Brock
Nov 14 '05 #1
4 1728
[snips]

On Tue, 09 Dec 2003 10:04:28 -0800, Brock wrote:
Hello all:

I apologize if this query seems a bit off-topic. But I couldn't think
of another place to post my message.

I would like to get an idea of how you all like to handle preprocessor
defines. Do you like to create a header file with all the associated
defines and then include it with every frickin' source file that's
created/modified, OR do you appreciate the ability to pass these on
the command line or from a makefile? Can you tell which method I
prefer?


Personally, I prefer a combination of the two.

Suppose I have a header, "porting.h" which contains all my system-specific
defines. Each section would, in turn, be wrapped in something like #ifdef
IS_UNIX ... #endif. Thus, to enable Unix compilation, you'd pass in a
command-line define such as -DIS_UNIX.

Why do I prefer this? Simple: I find including them in a header makes
for maximal readability and maintainability, without sacrificing the
flexibility to use a makefile to select between the options.
Nov 14 '05 #2
In <51**************************@posting.google.com > br******@gentex.com (Brock) writes:
I would like to get an idea of how you all like to handle preprocessor
defines. Do you like to create a header file with all the associated
defines and then include it with every frickin' source file that's
created/modified, OR do you appreciate the ability to pass these on
the command line or from a makefile?


Depending on their actual purpose, some macro defintions belong to the
source code, others to the compiler command line (which basically means
to the makefile).

For example, if you want to define a DEBUG macro, the right place is
the makefile, but the definition of something like MAX_ITEMS belongs to
the source code.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #3
Da*****@cern.ch (Dan Pop) wrote in message news:<br***********@sunnews.cern.ch>...
In <51**************************@posting.google.com > br******@gentex.com (Brock) writes:
I would like to get an idea of how you all like to handle preprocessor
defines. Do you like to create a header file with all the associated
defines and then include it with every frickin' source file that's
created/modified, OR do you appreciate the ability to pass these on
the command line or from a makefile?


Depending on their actual purpose, some macro defintions belong to the
source code, others to the compiler command line (which basically means
to the makefile).

For example, if you want to define a DEBUG macro, the right place is
the makefile, but the definition of something like MAX_ITEMS belongs to
the source code.


And I would say I totally agree with you. But that's the problem I say
that things like a DEBUG macro, or a BOARD_TYPE macro, or a hardware
peripheral-related macro should be in a makefile. I think we agree.
But I can't come up with a strong reason for saying so.
Brock
Nov 14 '05 #4
In <51**************************@posting.google.com > br******@gentex.com (Brock) writes:
Da*****@cern.ch (Dan Pop) wrote in message news:<br***********@sunnews.cern.ch>...
In <51**************************@posting.google.com > br******@gentex.com (Brock) writes:
>I would like to get an idea of how you all like to handle preprocessor
>defines. Do you like to create a header file with all the associated
>defines and then include it with every frickin' source file that's
>created/modified, OR do you appreciate the ability to pass these on
>the command line or from a makefile?


Depending on their actual purpose, some macro defintions belong to the
source code, others to the compiler command line (which basically means
to the makefile).

For example, if you want to define a DEBUG macro, the right place is
the makefile, but the definition of something like MAX_ITEMS belongs to
the source code.


And I would say I totally agree with you. But that's the problem I say
that things like a DEBUG macro, or a BOARD_TYPE macro, or a hardware
peripheral-related macro should be in a makefile. I think we agree.
But I can't come up with a strong reason for saying so.


The strong reason is that you don't want to touch the source code in order
to build the application in a different way and you don't want to put
source code related stuff in the building procedure (i.e. the makefile).

You certainly don't want to look into the makefile in order to understand
the source code or to look into the source code in order to understand
how the application is built.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: Da*****@ifh.de
Nov 14 '05 #5

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

Similar topics

11
by: Steven T. Hatton | last post by:
In the past there have been lengthy discussiions regarding the role of header files in C++. People have been very adamat about header files serving as in interface to the implementation. I do...
2
by: Karthik | last post by:
When I try to compile my VC++ program (am Using VS6.0). I get the following error in a header file ATLCONV.H. c:\program files\microsoft visual studio\vc98\atl\include\atlconv.h(52) : error...
3
by: pooja | last post by:
Suppose i have created a class c1 with f1()in c1.cpp and included this c1.cpp in file1.cpp file , which is also having main() by giving the statement #include "c1.cpp". the same i can do by...
0
by: Gregory Pietsch | last post by:
Hello comp.lang.c enthusiasts, Once while in a fit of pique, I thought I'd pull a Plauger. I have come up with an implementation of the functions declared in the standard C99 header fenv.h. I...
3
by: virgincita schmidtmann | last post by:
Sorry for inconvenience! I have two sourcefiles file1.c and file2.c. file1.c codes the standard BST (binary search tree) functions declarations and the basic struct definition. file2.c has...
7
by: The Cool Giraffe | last post by:
Please note that i do intend to use a header file. However, i'm not sure if it's really needed or just a convention. Suppose we have the following two files. // Something.h class Something {...
7
by: HT-Lab | last post by:
Hi All, Not strictly a C++ question but I am sure this is a common compile issue :-) I have a generic makefile (see below) that I would like update such that if I make some changes to a header...
2
by: Fabian Braennstroem | last post by:
Hi, I would like to delete a region on a log file which has this kind of structure: #------flutest------------------------------------------------------------ 498 1.0086e-03 2.4608e-04...
1
by: aryan | last post by:
Hi, I need to change the value of a const int variable defined in the header file of a library. The variable is used to dynamically set size of a char buffer within a class of the library. Its...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...

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.