From: Kevin Day Date: Thu, 18 Mar 2021 22:13:38 +0000 (-0500) Subject: Feature: support f_string_constant_t as a way to pass "const char *" as a parameter. X-Git-Tag: 0.5.3~89 X-Git-Url: https://git.kevux.org/?a=commitdiff_plain;h=6b4835e1062af012c631a43d6871cfae0d6a9e44;p=fll Feature: support f_string_constant_t as a way to pass "const char *" as a parameter. The parameter will have the return value and needs to be a pointer. Passing "const char **", the "const" is applied to "char **", which is not what is wanted. The desired logic is "(const char *) *", but that is not valid syntax. To achieve this, "const char *" is turned into the typedef "f_string_constant_t". This allows for "(const char *) *" to be used in the form of "f_string_constant_t *". This is a special, exceptional, case and there are no plans to support an "array of" or any of the completeness practices. --- diff --git a/level_0/f_string/c/string-common.h b/level_0/f_string/c/string-common.h index f05f164..87a9521 100644 --- a/level_0/f_string/c/string-common.h +++ b/level_0/f_string/c/string-common.h @@ -44,6 +44,27 @@ extern "C" { #endif // _di_f_string_t_ /** + * Define the constant string type. + * + * This is needed when passing a constant string as a function argument. + * This cannot be allocated or deallocated. + * This is provided for compatibility with some projects that return "const char *". + * + * GCC errors such as: "warning: assignment discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]" can be avoided using this. + * + * Do not confuse this with "const f_string_t". + * When "const f_string_t * xxx" is passed to a function, then "xxx" cannot be changed. + * When "f_string_constant_t * xxx" is passed to a function, then "xxx" can be changed. + */ +#ifndef _di_f_string_constant_t_ + typedef const char *f_string_constant_t; + + #define f_string_constant_t_initialize 0 + + #define f_macro_string_constant_t_clear(string) string = 0; +#endif // _di_f_string_t_ + +/** * Define the end of line character. * FLL forbids '\r' and '\r\n' as end of line characters, \r will be silently ignored. */