lkml.org 
[lkml]   [2019]   [Nov]   [12]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [alsa-devel] [PATCH v6 5/8] ALSA: Avoid using timespec for struct snd_rawmidi_status
On Tue, 12 Nov 2019 21:04:10 +0100,
Arnd Bergmann wrote:
>
> On Tue, Nov 12, 2019 at 5:38 PM Takashi Iwai <tiwai@suse.de> wrote:
> > On Tue, 12 Nov 2019 16:16:39 +0100, Arnd Bergmann wrote:
> > > +#ifndef __KERNEL__
> > > struct snd_rawmidi_status {
> > > int stream;
> > > + unsigned char pad1[sizeof(time_t) - sizeof(int)];
> > > struct timespec tstamp; /* Timestamp */
> > > size_t avail; /* available bytes */
> > > size_t xruns; /* count of overruns since last status (in bytes) */
> > > unsigned char reserved[16]; /* reserved for future use */
> > > };
> >
> > Can we use union instead of padding? Something like:
> >
> > struct snd_rawmidi_status {
> > union {
> > int stream;
> > time_t stream_alignment;
> > };
> > struct timespec tstamp; /* Timestamp */
> > ....
>
> I think this would work most of the time, though I don't feel this is more
> readable than the other version.
>
> More importantly, it requires compiling user applications with GNU extensions
> (--std=gnu89 or higher) or C11, but not C99, so this could be a problem
> for some applications.

OK, fair enough.

> If you feel there is a problem with the padding syntax, how about enclosing
> it in a typedef like:
>
> typedef struct { char pad[sizeof(time_t) - sizeof(int)]; } __time_pad;
>
> This typedef could be used in several structures from the other patches
> as well.

Yes, that improves the readability.


thanks,

Takashi

\
 
 \ /
  Last update: 2019-11-12 21:26    [W:0.053 / U:2.180 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site