[v4,05/12] Rephrase section about constants

Submitted by Christophe de Dinechin on Feb. 15, 2018, 4:06 p.m.

Details

Message ID 20180215160625.75406-6-christophe@dinechin.org
State New
Headers show
Series "Updates to the style guide" ( rev: 3 ) in Spice

Not browsing as part of any series.

Commit Message

Christophe de Dinechin Feb. 15, 2018, 4:06 p.m.
From: Christophe de Dinechin <dinechin@redhat.com>

The indent of the rephrasing is that:

- If you have a single constant, use const, e.g. (visible in debugger)
    const unsigned max_stuff = 42;

- If you have multiple constants, prefer enums over #define, as
    already suggested later in the guide:
    enum {
       A = 0,
       B = 42,
       C = -1
    }

Signed-off-by: Christophe de Dinechin <dinechin@redhat.com>
---
 docs/spice_style.txt | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/docs/spice_style.txt b/docs/spice_style.txt
index 3bc70570..996c5cd9 100644
--- a/docs/spice_style.txt
+++ b/docs/spice_style.txt
@@ -171,7 +171,9 @@  If a switch case falls through (i.e. does not end with a `break`), annotate it w
 Defining Constant values
 ------------------------
 
-Use defines for constant values for improving readability and ease of changes. Alternatively, use global `const` variables.
+Use defines for constant values for improving readability and ease of changes.
+Alternatively, use global `const` variables for individual values.
+If multiple related constants are to be defined, consider the use of enumerations with initializers.
 
 Short functions
 ---------------