Difference between revisions of "Cpp Coding Standards/TYPE"

From Apache OpenOffice Wiki
Jump to: navigation, search
m (Cpp Coding Standards/Topics/TYPE moved to Cpp Coding Standards/Type Safety: Improve Cpp_Coding_Standards structure.)
m
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
== Type Safety ==
+
== Type Safety (TYPE) ==
Casts and type recognition
+
''Casts and type recognition.''
----
+
=== Summary ===
+
==== TypesNotRepresentations ====
+
Rely on types, not on representations. Don't think in bits, don't memcpy non-PODs.
+
  
==== NoCStyleCasts ====
+
===== Types, not Representations <span id="NoRepr">(NoRepr)</span> =====
Don't use C-Style casts, but the C++ casts.
+
Rely on types, not on representations. Don't think in bits, don't memcpy non-PODs. [[/NoRepr|-> Details]]
  
==== AvoidPtrStaticCasts ====
+
===== No <code>switch</code> on Types <span id="NoSwitch">(NoSwitch)</span> =====
Use dynamic_cast instead of  static_cast when treating pointers polymorphically.
+
Don't use switch, when the cases represent types. Prefer polymorphism. [[/NoSwitch|-> Details]]
  
==== NoTypeSwitching ====
+
===== No C-Style Casts <span id="CCast">(CCast)</span> =====
Don't use switch, when the cases represent types. Prefer polymorphism.
+
Don't use C-Style casts, but the C++ casts. [[/CCast|-> Details]]
  
 +
===== Avoid <code>static_cast</code> on Pointers <span id="StacaPtr">(StacaPtr)</span> =====
 +
Use dynamic_cast instead of  static_cast when treating pointers polymorphically. [[/StacaPtr|-> Details]]
 
----
 
----
=== Related Rules ===
+
==== Related Rules ====
* [[../CLSDESIGN#NoImplicitConversions | CLSDESIGN:NoImplicitConversions]]
+
* No Implicit Conversions [[../CLSDESIGN#NoConv|-> CLSDESIGN:NoConv]]
----
+
=== Explanations ===
+
  
 
----
 
----
 
[[Category:Coding Standards]]
 
[[Category:Coding Standards]]

Latest revision as of 09:30, 23 May 2007

Type Safety (TYPE)

Casts and type recognition.

Types, not Representations (NoRepr)

Rely on types, not on representations. Don't think in bits, don't memcpy non-PODs. -> Details

No switch on Types (NoSwitch)

Don't use switch, when the cases represent types. Prefer polymorphism. -> Details

No C-Style Casts (CCast)

Don't use C-Style casts, but the C++ casts. -> Details

Avoid static_cast on Pointers (StacaPtr)

Use dynamic_cast instead of static_cast when treating pointers polymorphically. -> Details


Related Rules


Personal tools