Groups | Search | Server Info | Keyboard shortcuts | Login | Register
Groups > comp.programming.threads > #1130
| From | Jens Gustedt <jens.gustedt@loria.fr> |
|---|---|
| Newsgroups | comp.lang.c, comp.programming.threads |
| Subject | Re: Trivial C11 threads.h wrapper (public domain) |
| Date | 2012-10-01 00:37 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <5068C9C3.6090502@loria.fr> (permalink) |
| References | <slrnk67ihu.3ts.nuclear@goat.mutantstargoat.com> <5065EAFD.1050102@loria.fr> <5068B604.9020606@web.de> <lnwqzbryia.fsf@nuthaus.mib.org> |
Cross-posted to 2 groups.
Am 30.09.2012 23:28, schrieb Keith Thompson:
> Markus Elfring <Markus.Elfring@web.de> writes:
>>> There is already an implementation of C11 threads as a wrapper around
>>> POSIX threads that is publicly available.
>>
>> I would interpret source code like the following as an update candidate.
>
> I'm not sure what you mean by "update candidate".
>
>> http://p99.gforge.inria.fr/p99-html/p99__threads_8h_source.html :
>> ...
>> 00633 // 7.26.4 Mutex functions
>> 00634
>> 00638 p99_inline
>> 00639 void mtx_destroy(mtx_t *p00_mtx) {
>> 00640 (void)pthread_mutex_destroy(&P99_ENCP(p00_mtx));
>> 00641 }
>> ...
>>
>>
>> How do think about to get rid of the cast to the return type "void" in
>> such use cases?
>
> It doesn't matter much. The POSIX pthread_mutex_destroy() function
> returns an int result; the C11 mtx_destroy() function returns void.
> The (void) cast in this particular implementation is probably
> there to silence a compiler warning about the result of the call
> being discarded. The semantics are exactly the same with or without
> the cast.
Exactly, in particular there are some linux systems where the headers
are annotated with gcc extensions that make it difficult to ignore the
return of a system function.
And if you (Markus) refer to the fact of "casting a return type", this
is something completely different from "casting a function pointer to
a function type with a different return type". In one case the
compiler is supposed to convert the actual return type into something
different (with well defined rules) and in the other case you would
trick the compiler to believe that the return type would be of a
certain type (live on the stack, in a certain hardware register).
In the particular case of a cast with "(void)" has a special semantic
in the standard (here C11), namely to ignore the value an to evaluate
the expression just for its side effects:
> 6.3.2.2 void ... If an expression of any other type is evaluated as
> a void expression, its value or designator is discarded. (A void
> expression is evaluated for its side effects.)
and then in an example it even explains
> If a function call is evaluated as an expression statement for its
> side effects only, the discarding of its value may be made explicit by
> converting the expression to a void expression by means of a cast
And then, finally, the C11 standard leaves no way to get semantic of a
failed call accros, here. Do you see a way to use the return value in
some way?
Jens
Back to comp.programming.threads | Previous | Next — Previous in thread | Next in thread | Find similar
Trivial C11 threads.h wrapper (public domain) John Tsiombikas <nuclear@member.fsf.org> - 2012-09-27 03:38 +0000
Re: Trivial C11 threads.h wrapper (public domain) Keith Thompson <kst-u@mib.org> - 2012-09-26 20:50 -0700
Re: Trivial C11 threads.h wrapper (public domain) John Tsiombikas <nuclear@member.fsf.org> - 2012-09-27 04:15 +0000
Re: Trivial C11 threads.h wrapper (public domain) Lorenzo Beretta <lory.fulgi@infinito.it> - 2012-09-27 16:35 +0200
Re: Trivial C11 threads.h wrapper (public domain) John Tsiombikas <nuclear@member.fsf.org> - 2012-09-27 15:58 +0000
Re: Trivial C11 threads.h wrapper (public domain) Lorenzo Beretta <lory.fulgi@infinito.it> - 2012-09-27 18:27 +0200
Re: Trivial C11 threads.h wrapper (public domain) William Ahern <william@wilbur.25thandClement.com> - 2012-09-28 12:08 -0700
Re: Trivial C11 threads.h wrapper (public domain) Kaz Kylheku <kaz@kylheku.com> - 2012-09-28 19:38 +0000
Re: Trivial C11 threads.h wrapper (public domain) Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-09-28 15:50 -0400
Re: Trivial C11 threads.h wrapper (public domain) Lorenzo Beretta <lory.fulgi@infinito.it> - 2012-09-29 18:41 +0200
Re: Trivial C11 threads.h wrapper (public domain) Markus Elfring <Markus.Elfring@web.de> - 2012-09-27 13:45 +0200
Re: Trivial C11 threads.h wrapper (public domain) John Tsiombikas <nuclear@member.fsf.org> - 2012-09-27 16:14 +0000
Re: Trivial C11 threads.h wrapper (public domain) Markus Elfring <Markus.Elfring@web.de> - 2012-09-28 12:05 +0200
Re: Trivial C11 threads.h wrapper (public domain) Keith Thompson <kst-u@mib.org> - 2012-09-28 03:39 -0700
Re: Trivial C11 threads.h wrapper (public domain) James Kuyper <jameskuyper@verizon.net> - 2012-09-28 08:23 -0400
Re: Trivial C11 threads.h wrapper (public domain) John Tsiombikas <nuclear@member.fsf.org> - 2012-09-28 19:48 +0000
Re: Trivial C11 threads.h wrapper (public domain) Toby Douglass <a@b.com> - 2012-10-01 20:19 +0200
Re: Trivial C11 threads.h wrapper (public domain) James Kuyper <jameskuyper@verizon.net> - 2012-10-01 14:37 -0400
Re: Trivial C11 threads.h wrapper (public domain) Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-10-01 14:38 -0400
Re: Trivial C11 threads.h wrapper (public domain) Keith Thompson <kst-u@mib.org> - 2012-10-01 14:58 -0700
Re: Trivial C11 threads.h wrapper (public domain) Jens Gustedt <jens.gustedt@loria.fr> - 2012-09-28 20:22 +0200
Re: Trivial C11 threads.h wrapper (public domain) Markus Elfring <Markus.Elfring@web.de> - 2012-09-30 23:13 +0200
Re: Trivial C11 threads.h wrapper (public domain) Keith Thompson <kst-u@mib.org> - 2012-09-30 14:28 -0700
Re: Trivial C11 threads.h wrapper (public domain) Jens Gustedt <jens.gustedt@loria.fr> - 2012-10-01 00:37 +0200
Re: Trivial C11 threads.h wrapper (public domain) Jens Gustedt <jens.gustedt@loria.fr> - 2012-10-01 00:44 +0200
Re: Trivial C11 threads.h wrapper (public domain) Eric Sosman <esosman@ieee-dot-org.invalid> - 2012-09-30 19:48 -0400
Re: Trivial C11 threads.h wrapper (public domain) Jens Gustedt <jens.gustedt@loria.fr> - 2012-10-01 08:26 +0200
Re: Trivial C11 threads.h wrapper (public domain) Markus Elfring <Markus.Elfring@web.de> - 2012-10-01 11:25 +0200
Re: Trivial C11 threads.h wrapper (public domain) Jens Gustedt <jens.gustedt@loria.fr> - 2012-10-01 11:47 +0200
Re: Trivial C11 threads.h wrapper (public domain) Markus Elfring <Markus.Elfring@web.de> - 2012-10-01 12:05 +0200
Re: Trivial C11 threads.h wrapper (public domain) Jens Gustedt <jens.gustedt@loria.fr> - 2012-10-01 13:15 +0200
Clarification for interface specification "C11 threads.h" Markus Elfring <Markus.Elfring@web.de> - 2012-10-03 11:02 +0200
Re: Clarification for interface specification "C11 threads.h" Keith Thompson <kst-u@mib.org> - 2012-10-03 13:29 -0700
Re: Clarification for interface specification "C11 threads.h" Jens Gustedt <jens.gustedt@loria.fr> - 2012-10-04 13:35 +0200
Re: Clarification for interface specification "C11 threads.h" Markus Elfring <Markus.Elfring@web.de> - 2012-10-12 17:45 +0200
Re: Trivial C11 threads.h wrapper (public domain) Noob <root@127.0.0.1> - 2012-10-01 18:10 +0200
Re: Trivial C11 threads.h wrapper (public domain) Nick Bowler <nbowler@draconx.ca> - 2012-10-01 19:28 +0000
Re: Trivial C11 threads.h wrapper (public domain) Keith Thompson <kst-u@mib.org> - 2012-10-01 15:19 -0700
Re: Trivial C11 threads.h wrapper (public domain) Kaz Kylheku <kaz@kylheku.com> - 2012-10-01 23:57 +0000
Re: Trivial C11 threads.h wrapper (public domain) Jens Gustedt <jens.gustedt@loria.fr> - 2012-10-02 14:48 +0200
csiph-web