Giter Club home page Giter Club logo

Comments (6)

jtsiomb avatar jtsiomb commented on May 29, 2024

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.

horta avatar horta commented on May 29, 2024

Conversion between pointers and integers are implementation-defined

I should create a pull request.

from c11threads.

horta avatar horta commented on May 29, 2024

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.

horta avatar horta commented on May 29, 2024

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.

jtsiomb avatar jtsiomb commented on May 29, 2024

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.

horta avatar horta commented on May 29, 2024

Thanks a lot!

from c11threads.

Related Issues (14)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.