Coding standard

C

Carlos Martinez

Hi all:

I don't know if this is the best newsgroup to ask for this question, but
I don't find other.

I want to know about C++ Coding Standards and tools for verifing the code.

Thanks in advance.
 
M

mlimber

Carlos said:
I don't know if this is the best newsgroup to ask for this question, but
I don't find other.

I want to know about C++ Coding Standards and tools for verifing the code.

You might be interested in Sutter and Alexandrescu's _C++ Coding
Standards_. As for tools, I have used PC-Lint with some success (it's
not perfect, but it is quite useful). It doesn't allow customization
except by turning off certain messages, but it does support several
"standards" such as Scott Meyers' advice in _Effective C++_.

Cheers! --M
 
R

Roberto Waltman

P

Phlip

Roberto said:

I like the one that goes "never write a line of code without a failing test
case".

Specifically, the very first line I read in HICPPCM sez:

"Ensure all constructors supply an initial value (or invoke a constructor)
for each virtual base class, each non virtual base class and all non-static
data members."

Regardless of the wisdom of repeating the name of base classes, if they take
no arguments, that rule could be misconstrued to mean "supply every link to
other objects, that your object needs, in the constructor."

I know it doesn't say that. It should say "a constructor must do the minimum
to allow its destructor to call safely."

Test cases sometimes require you to construct an object _without_ its
navigable links to other objects. So the object should supply Set() or
Init() methods to then populate these objects, and it should work
well-enough without them.

I'm not sure why "An abstract class shall have no public constructors."

The point is that automated tests change these rules, and force you to obey
some of these rules.

And rules like "Use public derivation only" are flat-out wrong.
 
D

Dave Steffen

Roberto Waltman said:
See:

http://www.research.att.com/~bs/JSF-AV-rules.pdf
http://hem.passagen.se/erinyq/industrial/


With respect to verification tools, Gimpel's pc-lint is the only
affordable one I know.

Run, do not walk, to <http://valgrind.org/>. It's free, looks for
memory leaks and other bad behavior, can also do a lot of profiling,
and their customer support is orders of magnitude better than any
similar commercial product we've ever tried.

Unfortunately the platforms are limited to (I think) Linux on a few
popular hardware platforms.

----------------------------------------------------------------------
Dave Steffen, Ph.D.
Software Engineer IV Disobey this command!
Numerica Corporation
ph (970) 419-8343 x27
fax (970) 223-6797 - Douglas Hofstadter
dgsteffen at numerica dot us
 
E

Earl Purple

Roberto Waltman wrote:
/

what is this standard about:

Rule 3.3.4 Avoid casting to a virtual base class as this is
irreversible.
(QA C++ 3071)

Justification
Do not cast a pointer up an inheritance hierarchy to a virtual base
class as this pointer may not be cast back down the hierarchy.

class A {};

class B : public virtual A {};

A* foo()
{
B* b = new B;
return static_cast< A* >( b ); // casting to virtual
base
}

Reference ISO C++ 5.2.9/5, 5.2.9/8;
===========================================

As B is an A why else would you inherit from A (virtual or otherwise)
if you can't cast your pointer to an A? And it isn't irreversible, I
have reversed the cast, but most of the time you don't want to cast the
other way anyway.

I don't have the ISO standard so what exactly do those two paragraphs
state?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top