(setq-default indent-tabs-mode nil)Microsoft Visual C++ users should do the following:
Choose: Tools -- Options -- Tabs Then Set: "Tab size" to 8 and "Indent size" to 2, and indent using spaces.
-?
command line argument, are
provided to the program.
main
function should
always be declared with arguments, e.g.,
int main (int argc, char *argv[]) { [...] return 0; }
It should also return 0 on successful termination, and non-zero otherwise.
// $Id$It is not necessary to fill in the fields of the keyword string, or modify them when you edit a file that already has one. CVS does that automatically when you checkout or update the file.
To insert that string at the top of a file:
perl -pi -e 'if (! $o) {printf "// \$Id\$\n\n";}; $o = 1;' file
Please note that the Classinfo tools in OSE have been developed independently since the copies in ACE were made and thus they support new features not supported in the ACE version of the tools. Certain subtle changes were also made in the ACE copies for indicating sections, etc., which makes them different from the OSE documentation. Please see the ACE-doctools page for descriptions of these changes.
#endif
with a /* */
C-style comment. It
should correspond to the condition in the matching
#if
directive. For example,
#if defined (ACE_HAS_THREADS) # if defined (ACE_HAS_STHREADS) # include /**/ <synch.h> # include /**/ <thread.h> # define ACE_SCOPE_PROCESS P_PID # define ACE_SCOPE_LWP P_LWPID # define ACE_SCOPE_THREAD (ACE_SCOPE_LWP + 1) # else # define ACE_SCOPE_PROCESS 0 # define ACE_SCOPE_LWP 1 # define ACE_SCOPE_THREAD 2 # endif /* ACE_HAS_STHREADS */ #endif /* ACE_HAS_THREADS */
/**/
between an
#include
and
filename
, as shown in the above
example. This avoids dependency problems with Visual C++.
for
loops should look like:
for (size_t i = 0; i < Options::instance ()->spawn_count (); i++) spawn ();(though I prefer to always wrap the body of the loop in braces, to avoid surprises when other code or debugging statements are added, and to maintain sanity when the body consists of a macro, such as ACE_ASSERT:)
for (size_t i = 0; i < Options::instance ()->spawn_count (); i++) { ACE_ASSERT (spawn () == 0); }
Similarly, if
statements should have
a space after the ``if'', and no spaces just after
the opening parenthesis and just before the closing parenthesis.
.i
file. That file is conditionally included by both the
.h
file, for example:
class ACE_Export ACE_High_Res_Timer { [...] }; #if defined (__ACE_INLINE__) #include "ace/High_Res_Timer.i" #endif /* __ACE_INLINE__ */
and .cpp
file:
#define ACE_BUILD_DLL #include "ace/High_Res_Timer.h" #if !defined (__ACE_INLINE__) #include "ace/High_Res_Timer.i" #endif /* __ACE_INLINE__ */ ACE_ALLOC_HOOK_DEFINE(ACE_High_Res_Timer)
NOTE: It is very important to ensure than an
inline function will not be used before its definition is seen.
Therefore, the inline functions in the .i file should be arranged
properly. Some compilers, such as g++
with the
-Wall
option, will issue warnings for violations.
void object_addr (const ACE_INET_Addr &); // Sets <object_addr_> cache from <host> and <port>. ACE_INET_Addr &object_addr (void); // Returns the <ACE_INET_Addr> for this profile.
instead of the ``set_'' and ``get_'' form.
delete
to deallocate
memory that was allocated with malloc
.
Similarly, never associate free
with
new
.
ACE_NEW
or
ACE_NEW_RETURN
should be used to
allocate memory, and delete
should
be used to deallocate it. And be careful to use the correct form,
delete
or
delete []
to correspond to the
allocation.
ACE_NEW
or
ACE_NEW_RETURN
to allocate memory,
because they check for successful allocation and set errno
appropriately if it fails.
int
.
On all currently supported ACE platforms, it is safe to cast
a pointer to or from a long
.
ssize_t n_bytes; // Send multicast of one byte, enough to wake up server. if ((n_bytes = multicast.send ((char *) &reply_port, sizeof reply_port)) == -1)Write it like this:
ssize_t n_bytes = multicast.send ((char *) &reply_port, sizeof reply_port) // Send multicast of one byte, enough to wake up server. if (n_bytes == -1)
But, beware if the initialization is of a static variable. A static variable is only initialized the first time its declaration is seen. Of course, we should avoid using static variables at all.
if (test) { // true branch } else { // false branch }
is preferred over:
if (! test) { // false test branch } else { // true test branch }
int (foo)
. Instead, use
the ACE_static_cast macro:
return ACE_static_cast(size_t, this->count_) > that->size_;
// Disallow copying by not implementing the following . . . ACE_Object_Manager (const ACE_Object_Manager &); ACE_Object_Manager &operator= (const ACE_Object_Manager &);
If the class is a template class, then the
ACE_UNIMPLEMENTED_FUNC
macro should be used:
// = Disallow copying... ACE_UNIMPLEMENTED_FUNC (ACE_TSS (const ACE_TSS<TYPE> &)) ACE_UNIMPLEMENTED_FUNC (void operator= (const ACE_TSS<TYPE> &))
ACE_UNIMPLEMENTED_FUNC
can be used with non-template
classes as well. Though for consistency and maximum safety, it
should be avoided for non-template classes.
ACE_DEBUG
for printouts,
and ACE_OS::scanf/fprintf ()
for
file I/O. Avoid using iostreams because of implementation
differences across platforms.
ACE_OS
(static)
member functions instead of bare OS system calls.
ACE_SYNCH_MUTEX
macro,
instead of using one of the specific mutexes, such as
ACE_Thread_Mutex
. This provides
portability between threaded and non-threaded platforms.
ACE_Singleton
,
ACE_TSS_Singleton
, or as an
ACE_Cleanup
object. See the
ACE
Singleton.h
,
Object_Manager.h
, and
Managed_Object.h
header files for more information.
Static instances of built-in types, such as
int
or any pointer type, are fine.
Construction of static instance of a user-defined type should never spawn threads. Because order of construction of statics across files is not defined by the language, it is usually assumed that only one thread exists during static construction. This allows statics suchs as locks to be safely created. We do not want to violate this assumption.
ACE_NEW_RETURN (this->name_space_, LOCAL_NAME_SPACE, -1); if (ACE_LOG_MSG->op_status () != 0) ....This snip of code is from
ACE_Naming_Context
.
All failed constructors in ACE (should) call ACE_ERROR. This sets
the thread specific op_status, which can be checked
by the caller. This mechanism allows the caller to check for a failed
constructor without the requiring the constructor to throw
exceptions.