Re: [PATCH 1/2] parse-options: add int value pointer to struct option
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Sep 11, 2023, 19:19 UTC
- Message-ID
- <xmqq7cowv7pm.fsf@gitster.g>
- In-Reply-To
- <ZP4NrVeqMtFTLEuf@nand.local>
Taylor Blau <me@ttaylorr.com> writes:
Show 14 quoted lines
> callback, something like:
>
> struct option {
> /* ... */
> union {
> void *value;
> int *value_int;
> /* etc ... */
> } u;
> enum option_type t;
> };
>
> where option_type has some value corresponding to "void *", another for
> "int *", and so on.Yup, that does cross my mind, even though I would have used
union {
void *void_ptr;
int *int_ptr;
} value;or something without a rather meaningless 'u'.
Show 6 quoted lines
> Alternatively, perhaps you are thinking that we'd use both the value > pointer and the value_int pointer to point at potentially different > values in the same callback. I don't have strong feelings about it, but > I'd just as soon encourage us to shy away from that approach, since > assigning a single callback parameter to each function seems more > organized.
We have seen (with Peff's "-Wunused" work) that there are small number of cases that it would be handy for a callback to be told the locations of multiple external variables, but I do not think it would be a good solution to that problem to have "void *value" and "int value_int" next to each other and allow them to coexist, as it would work only when these multiple variables happen to be of the right types.