Re: [PATCH 1/2] parse-options: add int value pointer to struct option

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Am 11.09.23 um 21:19 schrieb Junio C Hamano:
> Taylor Blau <me@xxxxxxxxxxxx> writes:
>
>> 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'.

OK, but I neglected to ask what we would get out of throwing different
types into the same bin.  It complicates type safety by making it
impossible for the parser to distinguish the used type.  This will
become relevant once all int options are converted and value_int can be
made mandatory for them.  A named union also requires changing all
users.

It reduces the memory footprint, but only slightly.  Saving a few bytes
for objects with less than a hundred instances total doesn't seem worth
the downsides.

René





[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux