473,394 Members | 1,971 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,394 software developers and data experts.

including a large constants file

Hi,

If I have a large constants file and include that in a .cpp file will the
executable become large?

That is if I include a file with a bunch of constants does the executable
include all of the constants or just
the constants that are used in the .cpp file?

I am wanting a way so that only the constants that are used are included in
the executable and not the whole file.
I am trying to reduce the size of my executable.

I had trouble verifying this.

Thanks alot for any advice.

Many thanks,

John
Jul 22 '05 #1
9 1567
"john smith" <pr**************@charter.net> wrote in message
news:2h*******************@fe03.lga...
Hi,

If I have a large constants file and include that in a .cpp file will the
executable become large?
Define 'large'.

That is if I include a file with a bunch of constants does the executable
include all of the constants or just
the constants that are used in the .cpp file?
That depends entirely upon your compiler and platform.

I am wanting a way so that only the constants that are used are included in the executable and not the whole file.
Again this depends upon your compiler, and also upon the
context in which they're used. Some might be stored in
your program's image, some might become 'immediate' operands
of machine instructions.
I am trying to reduce the size of my executable.
None of what you ask is addressed by the language, so
we cannot answer conclusively.

I had trouble verifying this.

Thanks alot for any advice.


Consult your compiler documentation, and/or search your
compiler's support resources.

-Mike
Jul 22 '05 #2

"Mike Wahler" <mk******@mkwahler.net> wrote in message
news:gE*****************@newsread1.news.pas.earthl ink.net...
"john smith" <pr**************@charter.net> wrote in message
news:2h*******************@fe03.lga...
Hi,

If I have a large constants file and include that in a .cpp file will the executable become large?


Define 'large'.

That is if I include a file with a bunch of constants does the executable include all of the constants or just
the constants that are used in the .cpp file?


That depends entirely upon your compiler and platform.


I forgot to add: This also depends upon how you're defining
your constants. If you're defining const objects, what I
said before applies. If you're using #define, all that does
is give symbolic names to your values (it's merely a text-
substitution mechanism), and if you don't refer to the #defined
names, they should not enter into your code at all.

-Mike
Jul 22 '05 #3
john smith wrote:
If I have a large constants file and include that in a .cpp file,
will the executable become large?

That is if I include a file with a bunch of constants,
does the executable include all of the constants?
Or just the constants that are used in the .cpp file?

I am wanting a way so that
only the constants that are used are included in the executable
and not the whole file.
I am trying to reduce the size of my executable.
cat f.cc #include"physical.h"

using physical::unit::kilograms;
double v = 4.0*kilograms;
g++ -Wall -ansi -pedantic -O2 -S f.cc
cat f.s .file "f.cc"
.globl v
.data
.align 8
.type v, @object
.size v, 8
v:
.long 0
.long 1074790400
.section .note.GNU-stack,"",@progbits
.ident "GCC: (GNU) 3.4.1"

You can search the comp.lang.c++ archives
for the physical.h header file.
It contains hundreds of constant definitions
but my GNU optimizing C++ compiler
g++ --version

g++ (GCC) 3.4.1

reserves space only for v!
Jul 22 '05 #4
Mike Wahler wrote:
john smith wrote:
If I have a large constants file
and include that in a .cpp file,
will the executable become large?


Define 'large'.
That is, if I include a file with a bunch of constants,
does the executable include all of the constants?
Or just the constants that are used in the .cpp file?


That depends entirely upon your compiler and platform.


And which optimization options you invoke.
I am wanting a way so that only the constants that are used
are included in the executable and not the whole file.


Again this depends upon your compiler
and also upon the context in which they're used.
Some might be stored in your program's image,
some might become 'immediate' operands of machine instructions.
I am trying to reduce the size of my executable.


None of what you ask is addressed by the language
so we cannot answer conclusively.


No. that isn't quite right.
A good optimizing C++ compiler
will elide any constant definitions that it does not use.
A good optimizing C++ compiler
will combine any constants that it finds in numerical expressions
at compile time.
You should *not* cobble your code to compensate
for inferior implementations.
If you C++ compiler cannot perform these optimizations,
you should be shopping for a better C++ compiler.
Market forces and *not* ANSI/ISO standards
govern the quality of implementation.
Compiler developers must compete with each other for customers.
It is the programmers responsibility
to choose superior implementations
and driver inferior compiler developers out of business.
Jul 22 '05 #5
KTC
"E. Robert Tisdale" <E.**************@jpl.nasa.gov> for some
reason wrote:
Mike Wahler wrote:
None of what you ask is addressed by the language
so we cannot answer conclusively.
No. that isn't quite right.
A good optimizing C++ compiler
will elide any constant definitions that it does not use.
A good optimizing C++ compiler
will combine any constants that it finds in numerical

expressions at compile time.
You should *not* cobble your code to compensate
for inferior implementations.
If you C++ compiler cannot perform these optimizations,
you should be shopping for a better C++ compiler.
Market forces and *not* ANSI/ISO standards
govern the quality of implementation.
Compiler developers must compete with each other for customers.
It is the programmers responsibility
to choose superior implementations
and driver inferior compiler developers out of business.


I'm must be just getting confused with everything tonight. But
isn't Mike saying exactly what you're saying? That it's not the
standard that specify it but rather the implementation.

KTC

--
Experience is a good school but the fees are high.
- Heinrich Heine
Jul 22 '05 #6
KTC wrote:
E. Robert Tisdale wrote:
Mike Wahler wrote:
None of what you ask is addressed by the language
so we cannot answer conclusively.
No. that isn't quite right.
A good optimizing C++ compiler
will elide any constant definitions that it does not use.
A good optimizing C++ compiler will combine any constants
that it finds in numerical expressions at compile time.

You should *not* cobble your code to compensate
for inferior implementations.
If you C++ compiler cannot perform these optimizations,
you should be shopping for a better C++ compiler.
Market forces and *not* ANSI/ISO standards
govern the quality of implementation.
Compiler developers must compete with each other for customers.
It is the programmers responsibility
to choose superior implementations
and driver inferior compiler developers out of business.


I'm must be just getting confused with everything tonight.
But isn't Mike saying exactly what you're saying?


No.
I'm saying that we *can* answer conclusively.
That it's not the standard that specify it
but rather the implementation.


Mike Wahler and I agree on that part.
But the original poster, John Smith, requested,
"I am wanting a way so that
only the constants that are used are included in the executable
and not the whole file." I am saying that
that optimization is indeed what John Smith should expect
from a quality implementation.
He needs to find out whether or not his C++ compiler
can perform this optimization and, if it can't,
he needs to shop for a better C++ compiler.
Mike Wahler didn't say that. I don't know why.
Jul 22 '05 #7
KTC
"E. Robert Tisdale" <E.**************@jpl.nasa.gov> for some reason
wrote:

No.
I'm saying that we *can* answer conclusively.
That it's not the standard that specify it
but rather the implementation.


Mike Wahler and I agree on that part.
But the original poster, John Smith, requested,
"I am wanting a way so that
only the constants that are used are included in the executable
and not the whole file." I am saying that
that optimization is indeed what John Smith should expect
from a quality implementation.
He needs to find out whether or not his C++ compiler
can perform this optimization and, if it can't,
he needs to shop for a better C++ compiler.
Mike Wahler didn't say that. I don't know why.


Ah okay. The fact that it's half five in the morning and I haven't
slept yet might have had something to do with me not totally
understanding what you meant. =D

--
Experience is a good school but the fees are high.
- Heinrich Heine
Jul 22 '05 #8

"E. Robert Tisdale" <E.**************@jpl.nasa.gov> wrote in message
news:cr**********@nntp1.jpl.nasa.gov...
KTC wrote:
E. Robert Tisdale wrote:
Mike Wahler wrote:

None of what you ask is addressed by the language
so we cannot answer conclusively.

No. that isn't quite right.
A good optimizing C++ compiler
will elide any constant definitions that it does not use.
A good optimizing C++ compiler will combine any constants
that it finds in numerical expressions at compile time.

You should *not* cobble your code to compensate
for inferior implementations.
If you C++ compiler cannot perform these optimizations,
you should be shopping for a better C++ compiler.
Market forces and *not* ANSI/ISO standards
govern the quality of implementation.
Compiler developers must compete with each other for customers.
It is the programmers responsibility
to choose superior implementations
and driver inferior compiler developers out of business.


I'm must be just getting confused with everything tonight.
But isn't Mike saying exactly what you're saying?


No.
I'm saying that we *can* answer conclusively.
That it's not the standard that specify it
but rather the implementation.


Mike Wahler and I agree on that part.
But the original poster, John Smith, requested,
"I am wanting a way so that
only the constants that are used are included in the executable
and not the whole file." I am saying that
that optimization is indeed what John Smith should expect
from a quality implementation.
He needs to find out whether or not his C++ compiler
can perform this optimization and, if it can't,
he needs to shop for a better C++ compiler.
Mike Wahler didn't say that. I don't know why.


Because here we talk about the language, not particular
implementations. Also, John did not provide any evidence
that his constants were the source of the 'bloat' anyway.
Perhaps it's something else.

-Mike
Jul 22 '05 #9
john smith wrote:
Hi,

If I have a large constants file and include that in a .cpp file will the
executable become large? [snip]

As Mike said, constants may be eliminated, part of the executable, or
reside in the data area.
I am trying to reduce the size of my executable. Reorganizing constants may reduce the size of the sources but
may have little effect on the executable.

My primary method of reducing an executable is to:
** Reduce executable size if and only if the rest of the program
is working correctly, is robust, and either the customer is
complaining about the size or the executable is too big to
fit on the target platform.
1. Remove unused code.
2. Remove unwanted features and the code they occupy.
3. Combine common fragments into functions.
4. Change simple functions into inline macros.
These are functions whose contents take up as much executable
space as the call/return protocol.
5. Use assembly language functions to take advantage of special
processor instructions. Print out the compiler's assembly
language for the source function. Optimize it. Replace it
with yours only if there is a significant space savings.

I had trouble verifying this.

Thanks alot for any advice.

Many thanks,

John


--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library

Jul 22 '05 #10

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

Similar topics

3
by: MLH | last post by:
I make API calls to the sndPlaySound function, something like this... XX% = sndPlaySound(msound, MyParm) Several predefined system constants (or API intrinsic constants) have been recommended...
13
by: Andrew | last post by:
I use conditional compiler constants, set through the VBA IDE in Tools, <projectname> Properties, that I refer to throughout my code to control which code is used during development, and which...
4
by: Matthew Crema | last post by:
Hello, Say I have 1000 text files and each is a list of 32768 integers. I have written a C program to read this data into a large matrix. I am using fopen in combination with fscanf to read...
8
by: Marty | last post by:
Hi, I'm new to C#, I used to code in VB.NET. Where is the best place to declare all my constants and global objects in my C# project to have them accessible globally? I have an event logger...
0
by: Barry Newberger | last post by:
I am working on a Outlook COM project. For some reason win32com.client.constants quit working between runs of one of my test scripts. It's supposed to acquire attributes for all constants...
4
by: bcomeara | last post by:
I am writing a program which needs to include a large amount of data. Basically, the data are p values for different possible outcomes from trials with different number of observations (the p...
2
by: Leslie Sanford | last post by:
I want to define a set of floating point constants using templates insteand of macros. I'd like to determine whether these constants are floats or doubles at compile time. In my header file, I have...
21
by: FutureShock | last post by:
I have just recently started to use OOP for my web applications and am running into some head scratching issues. I wanted to have a separate file for all my configuration variables. Some of them...
54
by: shuisheng | last post by:
Dear All, I am always confused in using constants in multiple files. For global constants, I got some clues from http://msdn.microsoft.com/en-us/library/0d45ty2d(VS.80).aspx So in header...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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.