From bfc3dbae88dc70a832e82c5b44474fdf5a5e65a5 Mon Sep 17 00:00:00 2001 From: wm4 Date: Tue, 18 Sep 2012 16:08:17 +0200 Subject: options: simplify somewhat by introducing a union for option values The m_option_value union is supposed to contain a field for each possible option type (as long as it actually stores data). This helps avoiding silly temporary memory alocations. Using a pointer to an union and to a field of the union interchangeably should be allowed by standard C. --- m_option.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'm_option.h') diff --git a/m_option.h b/m_option.h index f05fe17bd4..2bd9054ac2 100644 --- a/m_option.h +++ b/m_option.h @@ -178,6 +178,25 @@ struct m_sub_options { #define CONF_TYPE_TIME (&m_option_type_time) #define CONF_TYPE_TIME_SIZE (&m_option_type_time_size) +// Possible option values. Code is allowed to access option data without going +// through this union. It serves for self-documentation and to get minimal +// size/alignment requirements for option values in general. +union m_option_value { + int flag; // not the C type "bool"! + int int_; + int64_t int64; + float float_; + double double_; + char *string; + char **string_list; + int imgfmt; + int afmt; + m_span_t span; + m_obj_settings_t *obj_settings_list; + double time; + m_time_size_t time_size; +}; + //////////////////////////////////////////////////////////////////////////// // Option type description -- cgit v1.2.3