Reputation: 49
I've read many posts on this and I can tell you (every post I've read makes this set of assumptions, so lets get it out of way early):
Code:
#if __STDC_VERSION__ >= 199901L
#define _XOPEN_SOURCE 600
#else
#define _XOPEN_SOURCE 500
#endif /* __STDC_VERSION__ */
#include <linux/soundcard.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#define uint unsigned int
struct KEYDATA
{
struct timestruct duration;
} ;
// output/display function
int main(void)
{
struct KEYDATA keyData[20];
keyData.duration.tv_nsec = 999;
return 0;
}
At compile time:
pi@raspberrypi:~/src/midi-timing $ gcc tmp.c -O2 -Wall -pedantic -o tmp -std=gnu99 -lrt
tmp.c:19:22: error: field ‘duration’ has incomplete type
struct timestruct duration;
^
tmp.c: In function ‘main’:
tmp.c:27:11: error: request for member ‘duration’ in something not a structure or union
keyData.duration.tv_nsec = 999;
^
tmp.c:25:19: warning: variable ‘keyData’ set but not used [-Wunused-but-set-variable]
struct KEYDATA keyData[20];
^
pi@raspberrypi:~/src/midi-timing $
I'll admit I'm a little rusty on my C programming, but there must be something here I'm not seeing. If you see the error, please let me know. Thanks.
Upvotes: 0
Views: 1658
Reputation: 1315
You need to replace timestruct
with timespec
#if __STDC_VERSION__ >= 199901L
#define _XOPEN_SOURCE 600
#else
#define _XOPEN_SOURCE 500
#endif /* __STDC_VERSION__ */
#include <linux/soundcard.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#define uint unsigned int
struct KEYDATA
{
//struct timestruct duration;
struct timespec duration;
} ;
// output/display function
int main(void)
{
struct KEYDATA keyData[20];
//keyData.duration.tv_nsec = 999;
keyData->duration.tv_nsec = 999;
return 0;
}
Upvotes: 1
Reputation: 1218
You've identified the type of duration
as struct timestruct
instead of struct timespec
. Simply fix this misspelling and I believe you should be fine.
Upvotes: 1