Shao Miller
5/16/2011 2:26:00 PM
On 5/16/2011 07:05, janus wrote:
>> Shao Miller
>> /* Join non-empty strings with a specified, non-empty delimiter string */
>> int join_strings_with_delim(
>> struct string * output_str,
>> const struct string * const * input_strings,
>> const unsigned int input_string_count,
>> const struct string * delim,
>> int allocation
>> ) {
>> int i;
>> size_t output_size;
>> char * buf;
>>
>> /* Check output string */
>> ...
>
> I am confuse... Could explain the following;
>
> const struct string * const * input_strings, # Having two consts and pointer symbol staggered
Absolutely, I'm happy to explain. :)
'input_strings' is a pointer ('*') to a 'const'-qualified pointer ('*')
to a 'const'-qualified 'struct string'.
( [ (const struct string) * const] * input_strings)
What does this madness mean? It means:
- 'input_strings' is not 'const'-qualified, so it can be changed. For
example, you could do:
input_strings++;
- 'input_strings' points to a pointer. _That_ pointer is
'const'-qualified, so it mustn't be changed. For example, you could not do:
input_strings[0] = ...
*input_strings = ...
- 'input_strings' points to a pointer, and _that_ pointer points to a
'struct string'. That 'struct string' is 'const'-qualified, so it
mustn't be changed. For example, you could not do:
input_strings[0][0].len = ...
(*input_strings)[0].len = ...
(*input_strings)->len = ...
(*(*input_strings)).len = ...