Skip to content

added guard to prevent re-defining names in C23 - #68

Open
aalmkainzi wants to merge 1 commit into
tinycthread:masterfrom
aalmkainzi:fix-c23
Open

added guard to prevent re-defining names in C23#68
aalmkainzi wants to merge 1 commit into
tinycthread:masterfrom
aalmkainzi:fix-c23

Conversation

@aalmkainzi

Copy link
Copy Markdown

C23 made stdlib.h define call_once, once_flag, and ONCE_FLAG_INIT.

because of this, tinycthread.c would not compile for me. with the message:

> gcc tinycthread.c -c
In file included from tinycthread.c:25:
tinycthread.h:460:21: error: conflicting types for ‘pthread_once_t’; have ‘__once_flag’
  460 |   #define once_flag pthread_once_t
      |                     ^~~~~~~~~~~~~~
In file included from /usr/include/pthread.h:26,
                 from tinycthread.h:87:
/usr/include/x86_64-linux-gnu/bits/pthreadtypes.h:53:30: note: previous declaration of ‘pthread_once_t’ with type ‘pthread_once_t’ {aka ‘int’}
   53 | typedef int __ONCE_ALIGNMENT pthread_once_t;
      |                              ^~~~~~~~~~~~~~
tinycthread.h:472:32: error: conflicting types for ‘pthread_once’; have ‘void(int *, void (*)(void))’
  472 |   #define call_once(flag,func) pthread_once(flag,func)
      |                                ^~~~~~~~~~~~
/usr/include/pthread.h:509:12: note: previous declaration of ‘pthread_once’ with type ‘int(pthread_once_t *, void (*)(void))’ {aka ‘int(int *, void (*)(void))’}
  509 | extern int pthread_once (pthread_once_t *__once_control,
      |            ^~~~~~~~~~~~

To fix this, I included stdlib.h in the tinycthread.h, and added guards before defining the conflicting names

@gyrovorbis gyrovorbis left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Thanks.

@gyrovorbis

Copy link
Copy Markdown

Oh whoops. Sorry to have approved. Thought this was my fork! Lmao

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

Successfully merging this pull request may close these issues.

2 participants