473,395 Members | 2,467 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,395 software developers and data experts.

Compiling for "Release Version"


When I'm writing my own code, compiling it and testing it out as I go
along, I usually compile as follows:

gcc *.c -ansi -pedantic -Wall -o executable

If I'm using 3rd-party libraries, I'll usually do the following:

gcc *.c -Wall -o executable

When I've already tested my code and I'm distributing it to other
people to use, I tend to tell them to compile as follows:

gcc *.c -o executable

If my code has been well-tested and I'm certain it works perfectly, I
compile as follows:

gcc *.c -O3 -D NDEBUG -s -o executable

I can understand why we don't use "-D NDEBUG" or "-s" when testing
because we want to catch asserts that go off, but I'm curious as to
whether there's any reason to shy away from using "-O3" (or any
optimisations for any compiler for that matter) in debugging version?
Nov 12 '08 #1
13 1742
Tomás Ó hÉilidhe wrote:
When I'm writing my own code, compiling it and testing it out as I go
along, I usually compile as follows:

gcc *.c -ansi -pedantic -Wall -o executable

If I'm using 3rd-party libraries, I'll usually do the following:

gcc *.c -Wall -o executable

When I've already tested my code and I'm distributing it to other
people to use, I tend to tell them to compile as follows:

gcc *.c -o executable

If my code has been well-tested and I'm certain it works perfectly, I
compile as follows:

gcc *.c -O3 -D NDEBUG -s -o executable

I can understand why we don't use "-D NDEBUG" or "-s" when testing
because we want to catch asserts that go off, but I'm curious as to
whether there's any reason to shy away from using "-O3" (or any
optimisations for any compiler for that matter) in debugging version?
Because optimized code can be very hard to debug. Depending on the compiler
and debugger you don't end up where you think you should, you can't inspect
variables as they might have been optimized away, you may not be able to see
the arguments to functions etc. As sone form of optimization usually is the
default, for debugging versions I tend to switch it off explicitly, eg.
with -O0.
Also the -g (for symbols in the executable) or whatever the compiler uses
for this, usually is not part of the default settings, so I'd switch it on
for the debug versions. For gcc even -g3.

Bye, Jojo
Nov 12 '08 #2
On 12 Nov, 07:27, Tomás Ó hÉilidhe <t...@lavabit.comwrote:
When I'm writing my own code, compiling it and testing it out as I go
along, I usually compile as follows:

* * gcc *.c -ansi -pedantic -Wall -o executable

If I'm using 3rd-party libraries, I'll usually do the following:

* * gcc *.c -Wall -o executable

When I've already tested my code and I'm distributing it to other
people to use, I tend to tell them to compile as follows:

* * gcc *.c -o executable

If my code has been well-tested and I'm certain it works perfectly, I
compile as follows:

* * gcc *.c -O3 -D NDEBUG -s -o executable

I can understand why we don't use "-D NDEBUG" or "-s" when testing
because we want to catch asserts that go off, but I'm curious as to
whether there's any reason to shy away from using "-O3" (or any
optimisations for any compiler for that matter) in debugging version?

Generally, it is a good idea to run your testsuite multiple
times with optimizations of different levels. If you use a debugger,
it can be painful when optimizations are on and that is
typically why they get turned off for testing. But it is
a bad idea not to test with the optimization on as well.

IOW, run both:

configure CFLAGS="-g" && make check
** and **
configure CFLAGS="-g -O3" && make check

(or, in your case, compile by hand and run your test suite
with both levels of optimization. Pray you don't need
to use a debugger on the optimized version.)
Nov 12 '08 #3
In article <97**********************************@c22g2000prc. googlegroups.com>,
Tomás Ó hÉilidhe <to*@lavabit.comwrote:
>I can understand why we don't use "-D NDEBUG" or "-s" when testing
because we want to catch asserts that go off, but I'm curious as to
whether there's any reason to shy away from using "-O3" (or any
optimisations for any compiler for that matter) in debugging version?
I strongly recommend using some optimisation when compiling new code,
because gcc (and other compilers) can often give better warnings when
they optimise. For example. optimisation may result in more analysis
of variable use, allowing the compiler to warn about an uninitialised
variable that it would not otherwise detect.

On the other hand, optimisation can make debuggers work less well,
often because a variable has no real existence in the optimised
version.

Generally I compile with -O and recompile without it if it causes
debugging problems.

-- Richard
--
Please remember to mention me / in tapes you leave behind.
Nov 12 '08 #4
On Nov 12, 2:27*am, Tomás Ó hÉilidhe <to*@lavabit.comwrote:
When I'm writing my own code, compiling it and testing it out as I go
along, I usually compile as follows:

* * gcc *.c -ansi -pedantic -Wall -o executable
That's too restrictive; it turns off a LOT of useful gcc features,
such as compound literals, 64-bit integers (long long), variable-
length arrays, boolean variables, variadic macros, inline functions,
etc. It doesn't even allow // comments or mixing of statements and
declarations!

If you want standard C, at least specify std=c99, like

gcc *.c -std=c99 -Wall -o executable

which at least gives you the C99 features.
If I'm using 3rd-party libraries, I'll usually do the following:

* * gcc *.c -Wall -o executable
That's good too.

Sebastian

Nov 12 '08 #5
On 12 Nov, 11:17, s0s...@gmail.com wrote:
On Nov 12, 2:27*am, Tomás Ó hÉilidhe <t...@lavabit.comwrote:
When I'm writing my own code, compiling it and testing it out as I go
along, I usually compile as follows:
* * gcc *.c -ansi -pedantic -Wall -o executable

That's too restrictive; it turns off a LOT of useful gcc features,
such as compound literals, 64-bit integers (long long), variable-
length arrays, boolean variables, variadic macros, inline functions,
etc. It doesn't even allow // comments or mixing of statements and
declarations!
none of which are portable to C89 (old standard) compilers.
You can go a long way without any of the features you
mention above. Using them may restrict the portability
of your code. C99 compilers are not yet universal.

If you want standard C, at least specify std=c99, like

* * gcc *.c -std=c99 -Wall -o executable

which at least gives you the C99 features.
If I'm using 3rd-party libraries, I'll usually do the following:
* * gcc *.c -Wall -o executable

That's good too.

--
Nick Keighley
Nov 12 '08 #6
s0****@gmail.com wrote:
On Nov 12, 2:27 am, Tomás Ó hÉilidhe <to*@lavabit.comwrote:
>When I'm writing my own code, compiling it and testing it out as I go
along, I usually compile as follows:

gcc *.c -ansi -pedantic -Wall -o executable

That's too restrictive; it turns off a LOT of useful gcc features,
such as compound literals, 64-bit integers (long long), variable-
length arrays, boolean variables, variadic macros, inline functions,
etc. It doesn't even allow // comments or mixing of statements and
declarations!
What if he needs his code to be compilable by compilers that don't
support all of those features? Compilers that support all features of
C99 are rare, compilers that support only C90 are not unheard of, and
compilers that support C99 incompletely don't all support the same C99
features. Even gcc, by it's own admission, doesn't fully support
variable length arrays (though I've yet to see a clear statement about
which aspects of VLAs they don't support correctly).
Nov 12 '08 #7
s0****@gmail.com writes:
On Nov 12, 2:27Â*am, Tomás Ó hÉilidhe <to*@lavabit.comwrote:
>When I'm writing my own code, compiling it and testing it out as I go
along, I usually compile as follows:

Â* Â* gcc *.c -ansi -pedantic -Wall -o executable

That's too restrictive; it turns off a LOT of useful gcc features,
such as compound literals, 64-bit integers (long long), variable-
length arrays, boolean variables, variadic macros, inline functions,
etc. It doesn't even allow // comments or mixing of statements and
declarations!
It has already been pointed out, but the OP might want that
restriction to be sure of compilation "almost everywhere".
If you want standard C, at least specify std=c99, like

gcc *.c -std=c99 -Wall -o executable
My view is that this is too permissive. It does not turn off gcc
extensions so your code is still not being checked for compliance. I
would add -pedantic to get only C99 and no extras.

--
Ben.
Nov 12 '08 #8
On Nov 12, 6:35*am, James Kuyper <ja*********@verizon.netwrote:
s0****@gmail.com wrote:
On Nov 12, 2:27 am, Tomás Ó hÉilidhe <to*@lavabit.comwrote:
When I'm writing my own code, compiling it and testing it out as I go
along, I usually compile as follows:
* * gcc *.c -ansi -pedantic -Wall -o executable
That's too restrictive; it turns off a LOT of useful gcc features,
such as compound literals, 64-bit integers (long long), variable-
length arrays, boolean variables, variadic macros, inline functions,
etc. It doesn't even allow // comments or mixing of statements and
declarations!

What if he needs his code to be compilable by compilers that don't
support all of those features?
I doubt it. He has pointed out in other threads that he's primarily
interested in Windows and Linux, so he may have access to compilers
such as gcc, Intel, lcc-win32, and Comeau, to name a few.

Sebastian

Nov 12 '08 #9


s0s...@gmail.com wrote:
On Nov 12, 6:35�am, James Kuyper <ja*********@verizon.netwrote:
s0****@gmail.com wrote:
On Nov 12, 2:27 am, Tom�s � h�ilidhe <to*@lavabit.comwrote:
>When I'm writing my own code, compiling it and testing it out as I go
>along, I usually compile as follows:
>� � gcc *.c -ansi -pedantic -Wall -o executable
That's too restrictive; it turns off a LOT of useful gcc features,
such as compound literals, 64-bit integers (long long), variable-
length arrays, boolean variables, variadic macros, inline functions,
etc. It doesn't even allow // comments or mixing of statements and
declarations!
What if he needs his code to be compilable by compilers that don't
support all of those features?

I doubt it. He has pointed out in other threads that he's primarily
interested in Windows and Linux, so he may have access to compilers
such as gcc, Intel, lcc-win32, and Comeau, to name a few.
Just because he has access to them doesn't mean he's willing to
restrict the portability of his code to such compilers; for instance,
I have access to gcc on all the platforms my code needs to work, but
I'm working to a contractual requirement that our delivered code must
"conform" to C90 (the people who wrote that requirement clearly did
not know how meaningless the term "conforming code" is in C - I try to
obey the spirit of that requirement, and not just the letter of it).

Only Thom�s can tell us what his actual needs are. The fact that he
can compile his code with the options listed implies that he's not
currently taking advantage of any of those C99 features.
Nov 12 '08 #10
On Nov 12, 3:41*pm, jameskuyper <ja*********@verizon.netwrote:
s0s...@gmail.com wrote:
On Nov 12, 6:35 am, James Kuyper <ja*********@verizon.netwrote:
s0****@gmail.com wrote:
On Nov 12, 2:27 am, Tom s h ilidhe <to*@lavabit.comwrote:
When I'm writing my own code, compiling it and testing it out as Igo
along, I usually compile as follows:
gcc *.c -ansi -pedantic -Wall -o executable
That's too restrictive; it turns off a LOT of useful gcc features,
such as compound literals, 64-bit integers (long long), variable-
length arrays, boolean variables, variadic macros, inline functions,
etc. It doesn't even allow // comments or mixing of statements and
declarations!
What if he needs his code to be compilable by compilers that don't
support all of those features?
I doubt it. He has pointed out in other threads that he's primarily
interested in Windows and Linux, so he may have access to compilers
such as gcc, Intel, lcc-win32, and Comeau, to name a few.

Just because he has access to them doesn't mean he's willing to
restrict the portability of his code to such compilers;
The portability of the code is always restricted, either with C89 or
with C99. While there are more C89 compilers, the currently available
C99 compilers already allow code to be portable among most relevant
platforms, and even some obscure ones.
for instance,
I have access to gcc on all the platforms my code needs to work, but
I'm working to a contractual requirement that our delivered code must
"conform" to C90 (the people who wrote that requirement clearly did
not know how meaningless the term "conforming code" is in C - I try to
obey the spirit of that requirement, and not just the letter of it).

Only Thom s can tell us what his actual needs are. The fact that he
can compile his code with the options listed implies that he's not
currently taking advantage of any of those C99 features.
Yes, but the interesting question is: why? Is it because he needs the
code to port to a coffee machine where there isn't a C99 compiler
available? Or is it because people in this group have suggested him
not to use the C99 features simply because it's not their version of
choice?

But, as you said, only Tomás can tell us what his requirements are,
so,

Tomás: are you planing to port to a platform where there isn't a
compiler that supports the features in question?

Sebastian

Nov 12 '08 #11
s0****@gmail.com wrote:
....
The portability of the code is always restricted, either with C89 or
with C99. While there are more C89 compilers, the currently available
C99 compilers already allow code to be portable among most relevant
platforms, and even some obscure ones.
If code is writtem to make use only of the common subset of C90 and C99,
it will still be portable to all of those compilers, and also to a great
many others. Making use of features specific to C89 restricts
portability, but there's little or no reason to do that except in legacy
software - most of those features were removed for a good reason.

Making use of features specific to C99 is more of a tradeoff - each of
those features were added because a significant number of people
actually wanted them to be added. However, every such feature you use
reduces the number of compilers which can compile your code correctly
(and makes it harder to identify which compilers those are). Because of
those trade-offs, it's perfectly reasonable to choose either strict C90,
strict C99, or any place in between those extremes, depending upon
circumstances. I prefer the extremes; choosing the right point somewhere
in the middle requires a judgment call, and I'm lousy at judgment calls
- YMMV.
Nov 13 '08 #12
� wrote:
When I'm writing my own code, compiling it and testing it out as I go
along, I usually compile as follows:

gcc *.c -ansi -pedantic -Wall -o executable

If I'm using 3rd-party libraries, I'll usually do the following:

gcc *.c -Wall -o executable

When I've already tested my code and I'm distributing it to other
people to use, I tend to tell them to compile as follows:

gcc *.c -o executable

If my code has been well-tested and I'm certain it works perfectly, I
compile as follows:

gcc *.c -O3 -D NDEBUG -s -o executable

I can understand why we don't use "-D NDEBUG" or "-s" when testing
because we want to catch asserts that go off, but I'm curious as to
whether there's any reason to shy away from using "-O3" (or any
optimisations for any compiler for that matter) in debugging version?
Normally I use CXXFLAGS="-ggdb3 -Wall -Wextra" when debugging,
CXXFLAGS="-O3" for release (using g++ as my compiler)
Nov 13 '08 #13
s0****@gmail.com wrote, On 12/11/08 23:29:
On Nov 12, 3:41 pm, jameskuyper <ja*********@verizon.netwrote:
>s0s...@gmail.com wrote:
<snip whether or not to use C99 features>
>Just because he has access to them doesn't mean he's willing to
restrict the portability of his code to such compilers;

The portability of the code is always restricted, either with C89 or
with C99. While there are more C89 compilers, the currently available
C99 compilers already allow code to be portable among most relevant
platforms, and even some obscure ones.
However, his customers may not be prepared to use them.

<snip>
>Only Thom s can tell us what his actual needs are. The fact that he
can compile his code with the options listed implies that he's not
currently taking advantage of any of those C99 features.

Yes, but the interesting question is: why? Is it because he needs the
<snip>

He stated that he was shipping code to people. That means he won't have
complete control over what compilers they choose to use. For example,
one customer might have spent a lot of money on an MSDN subscription and
get rather pissed off when told that they cannot use the compiler in it.
Another might be stuck on SCO 5.0.5 due to support for other SW and not
be able to get a modern version of gcc running on it (I know it was
giving me a lot of grief).
--
Flash Gordon
If spamming me sent it to sm**@spam.causeway.com
If emailing me use my reply-to address
See the comp.lang.c Wiki hosted by me at http://clc-wiki.net/
Nov 13 '08 #14

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

Similar topics

2
by: Amil Hanish | last post by:
I am trying to use XmlTextWriter. I write the xml data fine, but the file is missing the first line that shows the version and encoding: <?xml version="1.0" encoding="utf-8"?> Can the...
6
by: **Developer** | last post by:
I have a couple of instances where using "Auto" did not work so I tried the "A" version of the DLL and it works. Tried the "W" version and it doesn't. Anyone have any idea why that might...
3
by: Steve Franks | last post by:
I'm using Visual Studio 2005 RC and cannot figure out how to produce a "release" build. Am I doing something wrong? I'm wondering if perhaps MS locked out the ability to produce a release build...
3
by: gregory_may | last post by:
Is it possible to Obfuscate the Release build of my application as part of the compile/automatically? Thanks!
5
by: va | last post by:
When I create a web site (or personal web site starter kit) I don't see a "release" version in the configuation manager like a default Winforms application has. Does it not apply for Asp.net?
0
!NoItAll
by: !NoItAll | last post by:
So when I build a VB.net application an .exe appears in the BIN folder, in the OBJ\RELEASE folder, the Debug folder - and even a few other places. So which one of these do I ship to a customer -...
0
by: Alex B. | last post by:
I have an asp.net VS 2005 solution that was converted from VS 2003 that I have a deployment problem with. It compiles and runs fine, but now that I'm ready to deploy it I cannot set the website...
2
by: David Adams | last post by:
Hi, I am trying to build and deploy a web project from VS 2005 and am unable to select "Release" when I look at the configuration manager. I have several other projects that I am using that I...
3
by: jariwaladivyesh | last post by:
Hi frnds, i have simple XML doc <?xml version="1.0" encoding="utf-8"?> <?xml-stylesheet type="text/xsl" href="test.xsl"?> <data> <name> Divyesh Jariala</name> </data>
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: 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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
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...
0
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,...

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.