Comments (6)
Even the existing attempt to appease the compiler, with the double-cast, seems pointless and ugly. Adding even more cruft just isn't worth it. I'd say better pass that flag to disable the warning.
Leaving this bug report open, just in case I think about it some more and reconsider. But this is probably a won't-fix.
from c11threads.
Conversion between pointers and integers are implementation-defined
I should create a pull request.
from c11threads.
Actually, there is no compliant solution for that kind of code:
unsigned int *g(void) {
unsigned int *ptr = 0xdeadbeef;
/* ... */
return ptr;
}
I'm thinking about using _Thread_local
to statically store (per-thread) that integer. The downside is that this is C11, although gnu99 will probably have that implemented long-time ago.
from c11threads.
Musl has a seemingly working solution:
#include <threads.h>
#include <pthread.h>
#include <stdint.h>
_Noreturn void thrd_exit(int result)
{
__pthread_exit((void*)(intptr_t)result);
}
#include <stdint.h>
#include <threads.h>
#include <pthread.h>
int thrd_join(thrd_t t, int *res)
{
void *pthread_res;
__pthread_join(t, &pthread_res);
if (res) *res = (int)(intptr_t)pthread_res;
return thrd_success;
}
The plus side is that intptr_t
is C99.
from c11threads.
Yes conversions are implementation defined, but every implementation defines them as "if the bits you put into it fit, you'll get the same bits out of it".
Going through intptr_t
is the correct choice to silence the compiler.
from c11threads.
Thanks a lot!
from c11threads.
Related Issues (14)
- thrd_detach is spelled incorrectly HOT 1
- gcc timespec_get build error HOT 2
- Trap deadlocks
- thrd_sleep should return int HOT 1
- Duplicated declaration of timespec_get() on MacOSX HOT 2
- error: weak declaration of 'thrd_exit' must be public HOT 2
- <stdint.h> HOT 3
- C11THREADS_TIMEDLOCK_POLL_INTERVAL not defined HOT 1
- Test failure on FreeBSD HOT 5
- Windows threads support HOT 8
- CI HOT 1
- PTHREAD_MUTEX_TIMED_NP Isn't available outside of linux. HOT 6
- Use feature test macro for transparent drop-in HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from c11threads.