Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

conflicting types for timer_t 2_timing/10_timer #27

Open
aaronsgithub opened this issue Nov 29, 2022 · 3 comments
Open

conflicting types for timer_t 2_timing/10_timer #27

aaronsgithub opened this issue Nov 29, 2022 · 3 comments

Comments

@aaronsgithub
Copy link

Hey, this guide is amazing.

Just came across the following error in 2_timing/10_timer.

Linux users will suffer this error, but OS X users won't see it:
https://unix.stackexchange.com/questions/194480/why-is-timer-t-defined-in-time-h-on-linux-but-not-os-x

Changing timer_t to my_timer_t is one fix.

:~/another-c-library/illustrations/2_timing/10_timer$ make
gcc -O3 timer.c test_timer.c -o test_timer
In file included from /usr/include/time.h:47,
                 from timer.c:20:
/usr/include/x86_64-linux-gnu/bits/types/timer_t.h:7:19: error: conflicting types for ‘timer_t’
    7 | typedef __timer_t timer_t;
      |                   ^~~~~~~
In file included from timer.c:17:
timer.h:21:24: note: previous declaration of ‘timer_t’ was here
   21 | typedef struct timer_s timer_t;
      |                        ^~~~~~~
timer.c:30:10: error: conflicting types for ‘timer_init’
   30 | timer_t *timer_init(int repeat) {
      |          ^~~~~~~~~~
In file included from timer.c:17:
timer.h:28:10: note: previous declaration of ‘timer_init’ was here
   28 | timer_t *timer_init(int repeat);
      |          ^~~~~~~~~~
timer.c: In function ‘timer_init’:
timer.c:32:4: error: request for member ‘repeat’ in something not a structure or union
   32 |   t->repeat = repeat;
      |    ^~
timer.c:33:4: error: request for member ‘base’ in something not a structure or union
   33 |   t->base = t->time_spent = t->start_time = 0;
      |    ^~
timer.c:33:14: error: request for member ‘time_spent’ in something not a structure or union
   33 |   t->base = t->time_spent = t->start_time = 0;
      |              ^~
timer.c:33:30: error: request for member ‘start_time’ in something not a structure or union
   33 |   t->base = t->time_spent = t->start_time = 0;
      |                              ^~
timer.c: At top level:
timer.c:37:6: error: conflicting types for ‘timer_destroy’
   37 | void timer_destroy(timer_t *t) {
      |      ^~~~~~~~~~~~~
In file included from timer.c:17:
timer.h:31:6: note: previous declaration of ‘timer_destroy’ was here
   31 | void timer_destroy(timer_t *t);
      |      ^~~~~~~~~~~~~
timer.c:42:5: error: conflicting types for ‘timer_get_repeat’
   42 | int timer_get_repeat(timer_t *t) {
      |     ^~~~~~~~~~~~~~~~
In file included from timer.c:17:
timer.h:34:5: note: previous declaration of ‘timer_get_repeat’ was here
   34 | int timer_get_repeat(timer_t *t);
      |     ^~~~~~~~~~~~~~~~
timer.c: In function ‘timer_get_repeat’:
timer.c:43:11: error: request for member ‘repeat’ in something not a structure or union
   43 |   return t->repeat;
      |           ^~
timer.c: At top level:
timer.c:47:6: error: conflicting types for ‘timer_set_repeat’
   47 | void timer_set_repeat(timer_t *t, int repeat) {
      |      ^~~~~~~~~~~~~~~~
In file included from timer.c:17:
timer.h:37:6: note: previous declaration of ‘timer_set_repeat’ was here
   37 | void timer_set_repeat(timer_t *t, int repeat);
      |      ^~~~~~~~~~~~~~~~
timer.c: In function ‘timer_set_repeat’:
timer.c:48:4: error: request for member ‘repeat’ in something not a structure or union
   48 |   t->repeat = repeat;
      |    ^~
timer.c: At top level:
timer.c:52:6: error: conflicting types for ‘timer_subtract’
   52 | void timer_subtract(timer_t *t, timer_t *sub) {
      |      ^~~~~~~~~~~~~~
In file included from timer.c:17:
timer.h:40:6: note: previous declaration of ‘timer_subtract’ was here
   40 | void timer_subtract(timer_t *t, timer_t *sub);
      |      ^~~~~~~~~~~~~~
timer.c: In function ‘timer_subtract’:
timer.c:53:4: error: request for member ‘base’ in something not a structure or union
   53 |   t->base -= (sub->time_spent+sub->base);
      |    ^~
timer.c:53:18: error: request for member ‘time_spent’ in something not a structure or union
   53 |   t->base -= (sub->time_spent+sub->base);
      |                  ^~
timer.c:53:34: error: request for member ‘base’ in something not a structure or union
   53 |   t->base -= (sub->time_spent+sub->base);
      |                                  ^~
timer.c: At top level:
timer.c:56:6: error: conflicting types for ‘timer_add’
   56 | void timer_add(timer_t *t, timer_t *add) {
      |      ^~~~~~~~~
In file included from timer.c:17:
timer.h:42:6: note: previous declaration of ‘timer_add’ was here
   42 | void timer_add(timer_t *t, timer_t *add);
      |      ^~~~~~~~~
timer.c: In function ‘timer_add’:
timer.c:57:4: error: request for member ‘base’ in something not a structure or union
   57 |   t->base += (add->time_spent+add->base);
      |    ^~
timer.c:57:18: error: request for member ‘time_spent’ in something not a structure or union
   57 |   t->base += (add->time_spent+add->base);
      |                  ^~
timer.c:57:34: error: request for member ‘base’ in something not a structure or union
   57 |   t->base += (add->time_spent+add->base);
      |                                  ^~
timer.c: At top level:
timer.c:60:6: error: conflicting types for ‘timer_start’
   60 | void timer_start(timer_t *t) {
      |      ^~~~~~~~~~~
In file included from timer.c:17:
timer.h:45:6: note: previous declaration of ‘timer_start’ was here
   45 | void timer_start(timer_t *t);
      |      ^~~~~~~~~~~
timer.c: In function ‘timer_start’:
timer.c:63:4: error: request for member ‘start_time’ in something not a structure or union
   63 |   t->start_time = (tv.tv_sec * 1000000) + tv.tv_usec;
      |    ^~
timer.c: At top level:
timer.c:66:6: error: conflicting types for ‘timer_stop’
   66 | void timer_stop(timer_t *t) {
      |      ^~~~~~~~~~
In file included from timer.c:17:
timer.h:48:6: note: previous declaration of ‘timer_stop’ was here
   48 | void timer_stop(timer_t *t);
      |      ^~~~~~~~~~
timer.c: In function ‘timer_stop’:
timer.c:70:9: error: request for member ‘start_time’ in something not a structure or union
   70 |   v -= t->start_time;
      |         ^~
timer.c:71:4: error: request for member ‘time_spent’ in something not a structure or union
   71 |   t->time_spent += v;
      |    ^~
timer.c: At top level:
timer.c:74:8: error: conflicting types for ‘timer_ns’
   74 | double timer_ns(timer_t *t) {
      |        ^~~~~~~~
In file included from timer.c:17:
timer.h:54:8: note: previous declaration of ‘timer_ns’ was here
   54 | double timer_ns(timer_t *t);
      |        ^~~~~~~~
timer.c: In function ‘timer_ns’:
timer.c:75:15: error: request for member ‘repeat’ in something not a structure or union
   75 |   double r = t->repeat * 1.0;
      |               ^~
timer.c:76:16: error: request for member ‘time_spent’ in something not a structure or union
   76 |   double ts = t->time_spent + t->base;
      |                ^~
timer.c:76:32: error: request for member ‘base’ in something not a structure or union
   76 |   double ts = t->time_spent + t->base;
      |                                ^~
timer.c: At top level:
timer.c:80:8: error: conflicting types for ‘timer_us’
   80 | double timer_us(timer_t *t) {
      |        ^~~~~~~~
In file included from timer.c:17:
timer.h:55:8: note: previous declaration of ‘timer_us’ was here
   55 | double timer_us(timer_t *t);
      |        ^~~~~~~~
timer.c: In function ‘timer_us’:
timer.c:81:15: error: request for member ‘repeat’ in something not a structure or union
   81 |   double r = t->repeat * 1.0;
      |               ^~
timer.c:82:16: error: request for member ‘time_spent’ in something not a structure or union
   82 |   double ts = t->time_spent + t->base;
      |                ^~
timer.c:82:32: error: request for member ‘base’ in something not a structure or union
   82 |   double ts = t->time_spent + t->base;
      |                                ^~
timer.c: At top level:
timer.c:86:8: error: conflicting types for ‘timer_ms’
   86 | double timer_ms(timer_t *t) {
      |        ^~~~~~~~
In file included from timer.c:17:
timer.h:56:8: note: previous declaration of ‘timer_ms’ was here
   56 | double timer_ms(timer_t *t);
      |        ^~~~~~~~
timer.c: In function ‘timer_ms’:
timer.c:87:15: error: request for member ‘repeat’ in something not a structure or union
   87 |   double r = t->repeat * 1.0;
      |               ^~
timer.c:88:16: error: request for member ‘time_spent’ in something not a structure or union
   88 |   double ts = t->time_spent + t->base;
      |                ^~
timer.c:88:32: error: request for member ‘base’ in something not a structure or union
   88 |   double ts = t->time_spent + t->base;
      |                                ^~
timer.c: At top level:
timer.c:92:8: error: conflicting types for ‘timer_sec’
   92 | double timer_sec(timer_t *t) {
      |        ^~~~~~~~~
In file included from timer.c:17:
timer.h:57:8: note: previous declaration of ‘timer_sec’ was here
   57 | double timer_sec(timer_t *t);
      |        ^~~~~~~~~
timer.c: In function ‘timer_sec’:
timer.c:93:15: error: request for member ‘repeat’ in something not a structure or union
   93 |   double r = t->repeat * 1.0;
      |               ^~
timer.c:94:16: error: request for member ‘time_spent’ in something not a structure or union
   94 |   double ts = t->time_spent + t->base;
      |                ^~
timer.c:94:32: error: request for member ‘base’ in something not a structure or union
   94 |   double ts = t->time_spent + t->base;
      |                                ^~
In file included from /usr/include/x86_64-linux-gnu/sys/types.h:130,
                 from /usr/include/stdlib.h:394,
                 from test_timer.c:20:
/usr/include/x86_64-linux-gnu/bits/types/timer_t.h:7:19: error: conflicting types for ‘timer_t’
    7 | typedef __timer_t timer_t;
      |                   ^~~~~~~
In file included from test_timer.c:17:
timer.h:21:24: note: previous declaration of ‘timer_t’ was here
   21 | typedef struct timer_s timer_t;
      |                        ^~~~~~~
test_timer.c: In function ‘main’:
test_timer.c:36:28: warning: initialization of ‘void **’ from incompatible pointer type ‘timer_t *’ {aka ‘struct timer_s *’} [-Wincompatible-pointer-types]
   36 |   timer_t *overall_timer = timer_init(repeat_test);
      |                            ^~~~~~~~~~
test_timer.c:41:55: warning: passing argument 1 of ‘timer_get_repeat’ from incompatible pointer type [-Wincompatible-pointer-types]
   41 |     timer_t *copy_timer = timer_init(timer_get_repeat(overall_timer));
      |                                                       ^~~~~~~~~~~~~
      |                                                       |
      |                                                       void **
In file included from test_timer.c:17:
timer.h:34:31: note: expected ‘timer_t *’ {aka ‘struct timer_s *’} but argument is of type ‘void **’
   34 | int timer_get_repeat(timer_t *t);
      |                      ~~~~~~~~~^
test_timer.c:41:27: warning: initialization of ‘void **’ from incompatible pointer type ‘timer_t *’ {aka ‘struct timer_s *’} [-Wincompatible-pointer-types]
   41 |     timer_t *copy_timer = timer_init(timer_get_repeat(overall_timer));
      |                           ^~~~~~~~~~
test_timer.c:42:17: warning: passing argument 1 of ‘timer_start’ from incompatible pointer type [-Wincompatible-pointer-types]
   42 |     timer_start(copy_timer);
      |                 ^~~~~~~~~~
      |                 |
      |                 void **
In file included from test_timer.c:17:
timer.h:45:27: note: expected ‘timer_t *’ {aka ‘struct timer_s *’} but argument is of type ‘void **’
   45 | void timer_start(timer_t *t);
      |                  ~~~~~~~~~^
test_timer.c:46:16: warning: passing argument 1 of ‘timer_stop’ from incompatible pointer type [-Wincompatible-pointer-types]
   46 |     timer_stop(copy_timer);
      |                ^~~~~~~~~~
      |                |
      |                void **
In file included from test_timer.c:17:
timer.h:48:26: note: expected ‘timer_t *’ {aka ‘struct timer_s *’} but argument is of type ‘void **’
   48 | void timer_stop(timer_t *t);
      |                 ~~~~~~~~~^
test_timer.c:48:55: warning: passing argument 1 of ‘timer_get_repeat’ from incompatible pointer type [-Wincompatible-pointer-types]
   48 |     timer_t *test_timer = timer_init(timer_get_repeat(overall_timer));
      |                                                       ^~~~~~~~~~~~~
      |                                                       |
      |                                                       void **
In file included from test_timer.c:17:
timer.h:34:31: note: expected ‘timer_t *’ {aka ‘struct timer_s *’} but argument is of type ‘void **’
   34 | int timer_get_repeat(timer_t *t);
      |                      ~~~~~~~~~^
test_timer.c:48:27: warning: initialization of ‘void **’ from incompatible pointer type ‘timer_t *’ {aka ‘struct timer_s *’} [-Wincompatible-pointer-types]
   48 |     timer_t *test_timer = timer_init(timer_get_repeat(overall_timer));
      |                           ^~~~~~~~~~
test_timer.c:49:17: warning: passing argument 1 of ‘timer_start’ from incompatible pointer type [-Wincompatible-pointer-types]
   49 |     timer_start(test_timer);
      |                 ^~~~~~~~~~
      |                 |
      |                 void **
In file included from test_timer.c:17:
timer.h:45:27: note: expected ‘timer_t *’ {aka ‘struct timer_s *’} but argument is of type ‘void **’
   45 | void timer_start(timer_t *t);
      |                  ~~~~~~~~~^
test_timer.c:54:16: warning: passing argument 1 of ‘timer_stop’ from incompatible pointer type [-Wincompatible-pointer-types]
   54 |     timer_stop(test_timer);
      |                ^~~~~~~~~~
      |                |
      |                void **
In file included from test_timer.c:17:
timer.h:48:26: note: expected ‘timer_t *’ {aka ‘struct timer_s *’} but argument is of type ‘void **’
   48 | void timer_stop(timer_t *t);
      |                 ~~~~~~~~~^
test_timer.c:55:20: warning: passing argument 1 of ‘timer_subtract’ from incompatible pointer type [-Wincompatible-pointer-types]
   55 |     timer_subtract(test_timer, copy_timer);
      |                    ^~~~~~~~~~
      |                    |
      |                    void **
In file included from test_timer.c:17:
timer.h:40:30: note: expected ‘timer_t *’ {aka ‘struct timer_s *’} but argument is of type ‘void **’
   40 | void timer_subtract(timer_t *t, timer_t *sub);
      |                     ~~~~~~~~~^
test_timer.c:55:32: warning: passing argument 2 of ‘timer_subtract’ from incompatible pointer type [-Wincompatible-pointer-types]
   55 |     timer_subtract(test_timer, copy_timer);
      |                                ^~~~~~~~~~
      |                                |
      |                                void **
In file included from test_timer.c:17:
timer.h:40:42: note: expected ‘timer_t *’ {aka ‘struct timer_s *’} but argument is of type ‘void **’
   40 | void timer_subtract(timer_t *t, timer_t *sub);
      |                                 ~~~~~~~~~^~~
test_timer.c:56:15: warning: passing argument 1 of ‘timer_add’ from incompatible pointer type [-Wincompatible-pointer-types]
   56 |     timer_add(overall_timer, test_timer);
      |               ^~~~~~~~~~~~~
      |               |
      |               void **
In file included from test_timer.c:17:
timer.h:42:25: note: expected ‘timer_t *’ {aka ‘struct timer_s *’} but argument is of type ‘void **’
   42 | void timer_add(timer_t *t, timer_t *add);
      |                ~~~~~~~~~^
test_timer.c:56:30: warning: passing argument 2 of ‘timer_add’ from incompatible pointer type [-Wincompatible-pointer-types]
   56 |     timer_add(overall_timer, test_timer);
      |                              ^~~~~~~~~~
      |                              |
      |                              void **
In file included from test_timer.c:17:
timer.h:42:37: note: expected ‘timer_t *’ {aka ‘struct timer_s *’} but argument is of type ‘void **’
   42 | void timer_add(timer_t *t, timer_t *add);
      |                            ~~~~~~~~~^~~
test_timer.c:59:47: warning: passing argument 1 of ‘timer_ns’ from incompatible pointer type [-Wincompatible-pointer-types]
   59 |     printf( "time_spent: %0.4fns\n", timer_ns(test_timer) );
      |                                               ^~~~~~~~~~
      |                                               |
      |                                               void **
In file included from test_timer.c:17:
timer.h:54:26: note: expected ‘timer_t *’ {aka ‘struct timer_s *’} but argument is of type ‘void **’
   54 | double timer_ns(timer_t *t);
      |                 ~~~~~~~~~^
test_timer.c:61:19: warning: passing argument 1 of ‘timer_destroy’ from incompatible pointer type [-Wincompatible-pointer-types]
   61 |     timer_destroy(test_timer);
      |                   ^~~~~~~~~~
      |                   |
      |                   void **
In file included from test_timer.c:17:
timer.h:31:29: note: expected ‘timer_t *’ {aka ‘struct timer_s *’} but argument is of type ‘void **’
   31 | void timer_destroy(timer_t *t);
      |                    ~~~~~~~~~^
test_timer.c:62:19: warning: passing argument 1 of ‘timer_destroy’ from incompatible pointer type [-Wincompatible-pointer-types]
   62 |     timer_destroy(copy_timer);
      |                   ^~~~~~~~~~
      |                   |
      |                   void **
In file included from test_timer.c:17:
timer.h:31:29: note: expected ‘timer_t *’ {aka ‘struct timer_s *’} but argument is of type ‘void **’
   31 | void timer_destroy(timer_t *t);
      |                    ~~~~~~~~~^
test_timer.c:65:53: warning: passing argument 1 of ‘timer_ns’ from incompatible pointer type [-Wincompatible-pointer-types]
   65 |   printf( "overall time_spent: %0.4fns\n", timer_ns(overall_timer) );
      |                                                     ^~~~~~~~~~~~~
      |                                                     |
      |                                                     void **
In file included from test_timer.c:17:
timer.h:54:26: note: expected ‘timer_t *’ {aka ‘struct timer_s *’} but argument is of type ‘void **’
   54 | double timer_ns(timer_t *t);
      |                 ~~~~~~~~~^
test_timer.c:66:17: warning: passing argument 1 of ‘timer_destroy’ from incompatible pointer type [-Wincompatible-pointer-types]
   66 |   timer_destroy(overall_timer);
      |                 ^~~~~~~~~~~~~
      |                 |
      |                 void **
In file included from test_timer.c:17:
timer.h:31:29: note: expected ‘timer_t *’ {aka ‘struct timer_s *’} but argument is of type ‘void **’
   31 | void timer_destroy(timer_t *t);
      |                    ~~~~~~~~~^
make: *** [Makefile:4: test_timer] Error 1
@contactandyc
Copy link
Owner

Thanks for the time to look over this! I've been swamped for a while and haven't been able to put time into it like I would like. Would you like to make a pull request and I'll approve it and merge? If so, I can add you as a contributor.

@contactandyc
Copy link
Owner

Perhaps, this would be a good time to inject the ac_timer_t and point out the error. The ultimate library is prefixed with ac_ for (another c)

@aaronsgithub
Copy link
Author

I could do that.

I'll have to retrace my steps to find it again, but I think there was another issue with a Makefile in that section not working.

I'll have another look in the coming days when I have some time.

I saw on the README.md that you were hoping for contributors to join which is great. Perhaps you might consider enabling the discussions functionality on Github for this repo so that discussions of ideas could take place without necessarily creating an issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants