[m-rev.] proposed addition to coding standards

Peter Moulder Peter.Moulder at infotech.monash.edu.au
Sat Nov 15 17:32:07 AEDT 2003


On Thu, Nov 13, 2003 at 12:46:04AM +1100, Fergus Henderson wrote:
> I have noticed that while most files in the Mercury system are written
> in top-down order, others are written in bottom-up order.
> 
> Top-down ordering is usually a lot easier to read and understand than
> bottom-up ordering, so I propose that we specify this in our coding
> guidelines.

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; i.e. gcc-3.3 -O2 won't inline functions whose
definition appears after the call in the translation unit.

E.g. no inlining is done for the following file:

  static inline int bar(void);

  int foo(void) { return bar() + bar(); }

  static inline int bar(void) { return 42; }

despite the programmer telling the compiler in advance that bar is
static and intended to be inlined.

(bar is inlined in the above case with -O3.  I haven't experimented with
other options.  The claim "won't [ever] inline" is based on looking at -S
output rather than looking at gcc source code.)

This suggests that it may be beneficial to add something like the following
for c_coding_standard.html:

  <p>
  An exception may be made if <tt>bar()</tt> is a short function that should be
  inlined.  gcc -O2 appears never to do inlining where the call precedes
  the definition of the callee.


[Incidentally, I believe `<p>' ought to precede a paragraph even if the
paragraph comes after `</h2>' or `</ul>'.  One advantage is making the
paragraph easier to move.]

pjm.
--------------------------------------------------------------------------
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