Named fields in Structure Initialization

Sebastian Huber sebastian.huber at embedded-brains.de
Sat Aug 11 08:38:45 UTC 2012


On 10/08/12 21:26, Joel Sherrill wrote:
> Hi
>
> I was looking at the definition of the default pthread_attr_t
> in cpukit/posix/src/pthread.c. What's the consensus on
> explicitly naming fields as opposed to using order to resolve
> things.
>
> In the filesystem code, I think it is all named now. I was thinking
> of changing this over to something like this:
>
> const pthread_attr_t _POSIX_Threads_Default_attributes = {
>
>   .is_initialized = true,                       /* is_initialized */
>   .stackaddr = NULL,                            /* stackaddr */
>   .stacksize = 0,                               /* stacksize -- will 
> be adjusted to minimum */
>   .contentionscope = PTHREAD_SCOPE_PROCESS,     /* contentionscope */
>   .inheritsched = PTHREAD_INHERIT_SCHED,        /* inheritsched */
>   .schedpolicy = SCHED_FIFO,                    /* schedpolicy */
>   .schedparam = {                               /* schedparam */
>     .sched_priority = 2,                        /* sched_priority */
>     #if defined(_POSIX_SPORADIC_SERVER) || \
>         defined(_POSIX_THREAD_SPORADIC_SERVER)
>       .sched_ss_low_priority = 0,               /* 
> sched_ss_low_priority */
>       .sched_ss_repl_period = { 0L, 0 },        /* 
> sched_ss_repl_period */
>       .sched_ss_init_budget = { 0L, 0 }         /* 
> sched_ss_init_budget */
>     #endif
>   },
>
>   #if defined(_POSIX_THREAD_CPUTIME)
>     .cputime_clock_allowed = 1,                 /* 
> cputime_clock_allowed */
>   #endif
>
>   .detachstate = PTHREAD_CREATE_JOINABLE,       /* detachstate */
>
> };
>

I use the designated initializers (which are part of C99) mainly for 
documentation purposes.  We should remove the comments if we use the 
designated initializers.

-- 
Sebastian Huber, embedded brains GmbH

Address : Obere Lagerstr. 30, D-82178 Puchheim, Germany
Phone   : +49 89 18 90 80 79-6
Fax     : +49 89 18 90 80 79-9
E-Mail  : sebastian.huber at embedded-brains.de
PGP     : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.




More information about the devel mailing list