[m-rev.] proposed addition to coding standards
Fergus Henderson
fjh at cs.mu.OZ.AU
Fri Dec 5 17:45:19 AEDT 2003
On 16-Nov-2003, Peter Moulder <Peter.Moulder at infotech.monash.edu.au> wrote:
> On Sun, Nov 16, 2003 at 12:40:27AM +1100, Fergus Henderson wrote:
> > On 15-Nov-2003, Peter Moulder <Peter.Moulder at infotech.monash.edu.au> wrote:
> > >
> > > Note that following this proposal for C code means that gcc (3.3.2, -O2)
> > > will do no inlining of functions where the caller and callee are defined
> > > in the same source file, because gcc-3.3 -O2 won't inline functions whose
> > > definition appears after the call in the translation unit.
> >
> > In that case, we should compile our C files (runtime/*, trace/*) with gcc -O3.
>
> I gather that -O3 sometimes produces larger .o files than -O2
...
> It can ... make debugging impossible, since variables will
> no longer stay in a "home register".
Yes, `-O3' does have its disadvantages. My suggestion about that was a
bit of a knee-jerk response. Functions explicitly declared inline are
IMHO a reasonable exception from the rule about defining functions in
top-down order. I will update the C coding guidelines accordingly.
See patch below.
For functions not explicitly declared inline, they won't be inlined
anyway without `-O3', which we're not using. So for these functions
inlining does not seem to me to be sufficient reason for departing from
the recommended top-down ordering.
Incidentally, for the Mercury compiler itself, we should perhaps be
using -Os (optimize space) rather than -O2 or -O3. `-Os' was introduced
in egcs1.1, dated Sept 1998, which is old enough that we probably don't
even need to worry about autoconfing it. We could just document that
we no longer support GCC versions < egcs1.1.
----------
Estimated hours taken: 0.25
Branches: main
w3/information/developers/c_coding_standard.html:
Mention that inline functions are exception to the rule
that code should generally be order top-down, not bottom-up.
Workspace: /home/ceres/fjh/mercury
Index: w3/information/developers/c_coding_standard.html
===================================================================
RCS file: /home/mercury1/repository/w3/information/developers/c_coding_standard.html,v
retrieving revision 1.4
diff -u -d -r1.4 c_coding_standard.html
--- w3/information/developers/c_coding_standard.html 13 Nov 2003 13:06:11 -0000 1.4
+++ w3/information/developers/c_coding_standard.html 5 Dec 2003 07:39:31 -0000
@@ -103,7 +103,10 @@
Within each section, items should generally be listed in top-down order,
not bottom-up. That is, if foo() calls bar(), then the definition of
-foo() should precede the definition of bar().
+foo() should precede the definition of bar(). (An exception to this rule
+is functions that are explicitly declared inline; in that case, the
+definition should precede the call, to make it easier for the C compiler
+to perform the desired inlining.)
<h4>
1.2.2. Header files</h4>
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-reviews mailing list
post: mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the reviews
mailing list