From 07a465bd520f866c2d9bea486a5e4b6e45166835 Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Wed, 9 Dec 2020 19:39:57 -0600 Subject: [PATCH] Cleanup: use const more, but in a way that works with pointers. The standard practice is to specify const first. In the case of pointers, anything to the left of such a declaration represents what is being pointed to. This means const cannot be used in this case unless the pointer is intending to point to a constant. The const qualifier may instead be put after the pointer symbol '*' to designate that the pointer and not what is being pointed to is to be a constant. It seems that I tend to forget this behavior. This makes a pass at existing uses of such pointers, adding const in the appropriate way. --- level_1/fl_directory/c/private-directory.c | 4 ++-- level_2/fll_file/c/private-file.c | 4 ++-- level_3/fake/c/private-build.c | 22 +++++++++++----------- level_3/fake/c/private-fake.c | 22 +++++++++++----------- level_3/fake/c/private-make.c | 6 +++--- level_3/init/c/private-init.c | 8 ++++---- 6 files changed, 33 insertions(+), 33 deletions(-) diff --git a/level_1/fl_directory/c/private-directory.c b/level_1/fl_directory/c/private-directory.c index 286d157..e62fadb 100644 --- a/level_1/fl_directory/c/private-directory.c +++ b/level_1/fl_directory/c/private-directory.c @@ -23,7 +23,7 @@ extern "C" { f_string_length_t failures_used = recurse.failures ? recurse.failures->used : 0; { - f_string_dynamics_t *list[] = { + f_string_dynamics_t * const list[] = { &listing.block, &listing.character, &listing.regular, @@ -234,7 +234,7 @@ extern "C" { f_string_length_t failures_used = recurse.failures ? recurse.failures->used : 0; { - f_string_dynamics_t *list[] = { + f_string_dynamics_t * const list[] = { &listing.block, &listing.character, &listing.regular, diff --git a/level_2/fll_file/c/private-file.c b/level_2/fll_file/c/private-file.c index 2e2a171..d73fca3 100644 --- a/level_2/fll_file/c/private-file.c +++ b/level_2/fll_file/c/private-file.c @@ -30,7 +30,7 @@ extern "C" { const f_string_length_t path_length = strnlen(path, f_path_max); { - f_string_dynamics_t *list[] = { + f_string_dynamics_t * const list[] = { &listing.block, &listing.character, &listing.regular, @@ -127,7 +127,7 @@ extern "C" { const f_string_length_t path_length = strnlen(path, f_path_max); { - f_string_dynamics_t *list[] = { + f_string_dynamics_t * const list[] = { &listing.block, &listing.character, &listing.regular, diff --git a/level_3/fake/c/private-build.c b/level_3/fake/c/private-build.c index 6e98d06..a2a227a 100644 --- a/level_3/fake/c/private-build.c +++ b/level_3/fake/c/private-build.c @@ -1417,7 +1417,7 @@ extern "C" { if (F_status_is_error_not(*status)) { bool failed = F_false; - f_string_static_t *settings[] = { + f_string_static_t * const settings[] = { &setting->project_name, }; @@ -1583,7 +1583,7 @@ extern "C" { f_string_dynamics_t version_minor = f_string_dynamics_t_initialize; f_string_dynamics_t version_target = f_string_dynamics_t_initialize; - f_string_dynamics_t *settings_value[] = { + f_string_dynamics_t * settings_value[] = { &build_compiler, &build_indexer, &build_language, @@ -1791,7 +1791,7 @@ extern "C" { &version_target, }; - bool *settings_single_bool[] = { + bool * const settings_single_bool[] = { 0, 0, 0, @@ -1817,7 +1817,7 @@ extern "C" { &setting->search_static, }; - f_string_dynamic_t *settings_single_destination[] = { + f_string_dynamic_t * const settings_single_destination[] = { &setting->build_compiler, &setting->build_indexer, 0, @@ -1846,13 +1846,13 @@ extern "C" { &setting->version_minor, }; - uint8_t *settings_single_language[] = { + uint8_t * const settings_single_language[] = { 0, 0, &setting->build_language, }; - uint8_t *settings_single_version[] = { + uint8_t * const settings_single_version[] = { 0, 0, 0, @@ -1883,7 +1883,7 @@ extern "C" { }; // 1 = "yes" or "no", 2 = path/, 3 = literal, 4 = "bash", "c", or "c++", 5 = "major", "minor", or "micro". - uint8_t settings_single_type[] = { + const uint8_t settings_single_type[] = { 3, 3, 4, @@ -2088,19 +2088,19 @@ extern "C" { } { - f_string_t sources[] = { + const f_string_t sources[] = { fake_build_setting_default_version, fake_build_setting_default_version, fake_build_setting_default_version, }; - f_string_length_t lengths[] = { + const f_string_length_t lengths[] = { fake_build_setting_default_version_length, fake_build_setting_default_version_length, fake_build_setting_default_version_length, }; - f_string_dynamic_t *destinations[] = { + f_string_dynamic_t * const destinations[] = { &setting->version_major, &setting->version_minor, &setting->version_micro, @@ -2279,7 +2279,7 @@ extern "C" { fake_build_stage_sources_settings_length, }; - f_string_dynamic_t *values[] = { + f_string_dynamic_t * const values[] = { &stage->file_libraries_script, &stage->file_libraries_shared, &stage->file_libraries_static, diff --git a/level_3/fake/c/private-fake.c b/level_3/fake/c/private-fake.c index 8db25f2..fb6adf4 100644 --- a/level_3/fake/c/private-fake.c +++ b/level_3/fake/c/private-fake.c @@ -184,7 +184,7 @@ extern "C" { &data->path_sources_script, }; - f_string_dynamic_t **parameters_value[] = { + f_string_dynamic_t **const parameters_value[] = { parameters_value_0, parameters_value_1, parameters_value_2, @@ -237,7 +237,7 @@ extern "C" { fake_path_part_script_length, }; - f_string_dynamic_t *parameters_value[] = { + f_string_dynamic_t * const parameters_value[] = { &data->path_build_documents, &data->path_build_includes, &data->path_build_libraries, @@ -303,7 +303,7 @@ extern "C" { &data->file_documents_readme, }; - f_string_dynamic_t **parameters_value[] = { + f_string_dynamic_t **const parameters_value[] = { parameters_value_0, parameters_value_1, parameters_value_2, @@ -358,7 +358,7 @@ extern "C" { fake_file_readme_length, }; - f_string_dynamic_t *parameters_value[] = { + f_string_dynamic_t * const parameters_value[] = { &data->path_build_libraries_script, &data->path_build_libraries_shared, &data->path_build_libraries_static, @@ -384,7 +384,7 @@ extern "C" { if (data->path_work.used > 0) { { - f_string_dynamic_t *parameters_value[] = { + f_string_dynamic_t * const parameters_value[] = { &data->path_work_includes, &data->path_work_libraries, &data->path_work_programs, @@ -413,7 +413,7 @@ extern "C" { fake_path_part_programs_length, }; - f_string_dynamic_t *parameters_value[] = { + f_string_dynamic_t * const parameters_value[] = { &data->path_work_includes, &data->path_work_libraries, &data->path_work_programs, @@ -452,7 +452,7 @@ extern "C" { &data->path_work_programs_static, }; - f_string_dynamic_t **parameters_value[] = { + f_string_dynamic_t **const parameters_value[] = { parameters_value_0, parameters_value_1, }; @@ -486,7 +486,7 @@ extern "C" { fake_path_part_static_length, }; - f_string_dynamic_t *parameters_value[] = { + f_string_dynamic_t * const parameters_value[] = { &data->path_work_libraries_script, &data->path_work_libraries_shared, &data->path_work_libraries_static, @@ -507,7 +507,7 @@ extern "C" { } { - f_string_dynamic_t *parameters_value[] = { + f_string_dynamic_t * const parameters_value[] = { &data->path_build_documents, &data->path_build_includes, &data->path_build_libraries, @@ -604,7 +604,7 @@ extern "C" { fake_default_settings_length, }; - f_string_dynamic_t *parameters_value[] = { + f_string_dynamic_t * const parameters_value[] = { &data->fakefile, &data->process, &data->settings, @@ -746,7 +746,7 @@ extern "C" { fake_default_path_work_length, }; - f_string_dynamic_t *parameters_value[] = { + f_string_dynamic_t * const parameters_value[] = { &data->path_build, &data->path_data, &data->path_sources, diff --git a/level_3/fake/c/private-make.c b/level_3/fake/c/private-make.c index 8fbe3be..716b6c5 100644 --- a/level_3/fake/c/private-make.c +++ b/level_3/fake/c/private-make.c @@ -891,7 +891,7 @@ extern "C" { &data.mode, }; - f_string_dynamics_t *destination[] = { + f_string_dynamics_t * const destination[] = { &data_make->parameter.define, &data_make->parameter.mode, }; @@ -984,7 +984,7 @@ extern "C" { &data.settings, }; - f_string_dynamics_t *destination[] = { + f_string_dynamics_t * const destination[] = { &data_make->parameter.fakefile, &data_make->parameter.build, &data_make->parameter.data, @@ -1235,7 +1235,7 @@ extern "C" { fake_make_parameter_variable_work_length, }; - f_string_dynamics_t *reserved_value[] = { + f_string_dynamics_t * const reserved_value[] = { &data_make->parameter.build, &data_make->parameter.color, &data_make->parameter.data, diff --git a/level_3/init/c/private-init.c b/level_3/init/c/private-init.c index c810749..760ab4f 100644 --- a/level_3/init/c/private-init.c +++ b/level_3/init/c/private-init.c @@ -129,7 +129,7 @@ Consider the "*.device" files such that they are also use IKI. init_string_verbosity_length, }; - f_string_dynamic_t *parameter_value[] = { + f_string_dynamic_t * const parameter_value[] = { &cache, &cache, &cache, @@ -144,7 +144,7 @@ Consider the "*.device" files such that they are also use IKI. &cache, }; - bool *parameter_value_bool[] = { + bool * const parameter_value_bool[] = { 0, &setting_kernel->failsafe, 0, @@ -159,7 +159,7 @@ Consider the "*.device" files such that they are also use IKI. 0, }; - uint8_t *parameter_value_uint8[] = { + uint8_t * const parameter_value_uint8[] = { &setting_kernel->color, 0, &setting_kernel->mode, @@ -175,7 +175,7 @@ Consider the "*.device" files such that they are also use IKI. }; // @todo: create f_metric_t, such that it is an f_number_unsigned_t with an exponent type, such as: Y (yotta), Z (zetta), E (exa), P (peta), T (Tera), G (giga), M (mega), k (kilo), h (hecto), da (deca), (none), d (deci), c (centi), m (milli), μ (micro), n (nano), p (pico), f (femto), a (atto), z (zepto), and y (yocto). - f_number_unsigned_t *parameter_value_number_unsigned[] = { + f_number_unsigned_t * const parameter_value_number_unsigned[] = { 0, 0, 0, -- 1.8.3.1