|
Home > Archive > Debian Developers > July 2005 > (Re)Build problem with g++ 4.0
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
(Re)Build problem with g++ 4.0
|
|
| Juergen Salk 2005-07-07, 5:58 pm |
| Hi,
first of all: if this is not the appropriate list for this kind
of question, please give me pointer to better one.
I am having problems with rebuilding my dcmtk package with g++
4.0 on Sid. The problem seems to be related to type casting
between pthread_t and unsigned long int types and vice versa by
means of the `reinterpret_cast < > () operator'. With g++ 3.3 the
package builds fine right out of the box.
Here is a bare bone example to illustrate the problem:
jsa@charlotte:~$ cat thread2.cc
#include <pthread.h>
#include <unistd.h>
#include <stdlib.h>
void *thread_func(void *arg);
int main() {
pthread_t a_thread;
unsigned long dummy;
void *thread_result;
pthread_create(&a_thread, NULL, thread_func, NULL);
dummy = reinterpret_cast <unsigned long> (a_thread);
pthread_join(a_thread, &thread_result);
exit(EXIT_SUCCESS);
}
void *thread_func(void *arg) {
sleep(3);
pthread_exit(0);
}
jsa@charlotte:~$ /usr/bin/g++-3.3 -Wall -D_REENTRANT thread2.cc -o thread2 -lpthread
jsa@charlotte:~$ /usr/bin/g++-4.0 -Wall -D_REENTRANT thread2.cc -o thread2 -lpthread
thread2.cc: In function 'int main()':
thread2.cc:13: error: invalid cast from type 'pthread_t' to type 'long unsigned int'
jsa@charlotte:~$
Any ideas?
Regards - Juergen
--
GPG A997BA7A | 87FC DA31 5F00 C885 0DC3 E28F BD0D 4B33 A997 BA7A
| |
| Steinar H. Gunderson 2005-07-07, 5:58 pm |
| On Thu, Jul 07, 2005 at 11:57:23PM +0200, Juergen Salk wrote:
> dummy = reinterpret_cast <unsigned long> (a_thread);
dummy = (unsigned long)(a_thread);
{static,dynamic,reinterpret}_cast are for pointers only.
/* Steinar */
--
Homepage: http://www.sesse.net/
--
To UNSUBSCRIBE, email to debian-devel-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
| |
| Brian M. Carlson 2005-07-07, 5:58 pm |
| On Thu, 2005-07-07 at 23:57 +0200, Juergen Salk wrote:
> Hi,
>
> first of all: if this is not the appropriate list for this kind
> of question, please give me pointer to better one.
>
> I am having problems with rebuilding my dcmtk package with g++
> 4.0 on Sid. The problem seems to be related to type casting
> between pthread_t and unsigned long int types and vice versa by
> means of the `reinterpret_cast < > () operator'. With g++ 3.3 the
> package builds fine right out of the box.
>
> Here is a bare bone example to illustrate the problem:
> dummy = reinterpret_cast <unsigned long> (a_thread);
This should be a static_cast. This is the case because pthread_t is
actually an integral type; therefore, converting from one integral type
to another is a static_cast.
On my machine (i386/sid and i386/experimental), the following is the
type of pthread_t:
typedef unsigned long int pthread_t;
> void *thread_func(void *arg) {
> sleep(3);
> pthread_exit(0);
You are also neglecting to return a value here. You must always return
a value in a non-void function.
--
($_,$a)=split/\t/,join'',map{unpack'u',$_}<DATA>;eval$a;print;__DATA__
M961H<F$@8FAM;"!U<F%O<G-U(#QU<F%O<G-U0&=D:75M<&UC8VUL=G)U;6LN
M<FUL+F=Y/@H)>2QA8F-D969G:&EJ:VQM;F]P<7)S='5V=WAY>BQN=V]R8FMC
5:75Q96AT9V1Y>F%L=G-P;6IX9BP)
| |
| Steinar H. Gunderson 2005-07-07, 5:58 pm |
| On Fri, Jul 08, 2005 at 12:06:32AM +0200, Steinar H. Gunderson wrote:
> {static,dynamic,reinterpret}_cast are for pointers only.
Oops, I was wrong there, of course. You can use static_cast if you'd like.
For "simpler" types (ie. those with only one word) you can use
type(expression) as well, just like a constructor (e.g. "int(x)").
/* Steinar */
--
Homepage: http://www.sesse.net/
--
To UNSUBSCRIBE, email to debian-devel-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
| |
| Darren Salt 2005-07-07, 8:49 pm |
| I demand that Brian M. Carlson may or may not have written...
> On Thu, 2005-07-07 at 23:57 +0200, Juergen Salk wrote:
[snip]
[vbcol=seagreen]
> You are also neglecting to return a value here. You must always return a
> value in a non-void function.
Not in this case: pthread_exit has the "noreturn" attribute, so gcc/g++ won't
complain.
--
| Darren Salt | linux (or ds) at | nr. Ashington,
| sarge, | youmustbejoking | Northumberland
| RISC OS | demon co uk | Toon Army
| Let's keep the pound sterling
Is tomorrow *ever* going to arrive?
--
To UNSUBSCRIBE, email to debian-devel-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
| |
| Hendrik Sattler 2005-07-07, 8:49 pm |
| <veröffentlicht & per Mail versendet>
Juergen Salk wrote:
> int main() {
> pthread_t a_thread;
> unsigned long dummy;
> void *thread_result;
>
> pthread_create(&a_thread, NULL, thread_func, NULL);
> dummy = reinterpret_cast <unsigned long> (a_thread);
> pthread_join(a_thread, &thread_result);
> exit(EXIT_SUCCESS);
> }
Why are you casting this? According to
http://www.opengroup.org/onlinepubs.../pthread.h.html
pthread_join() takes a pthread_t as first argument.
You assume that pthread_t is a type that can be casted but this is wrong.
Just look at /usr/include/pthread.h:
extern pthread_t pthread_self (void) __THROW;
Be happy that gcc4 makes you aware of a coding error.
HS
| |
| Hendrik Sattler 2005-07-07, 8:49 pm |
| <veröffentlicht & per Mail versendet>
Juergen Salk wrote:
[...]
Cited the wrong file for pthread_t definition :-/
It's
/usr/include/bits/pthreadtypes.h:typedef unsigned long int pthread_t;
Still, no casting is needed (gcc4 probably wants to tell you that other
systems might define pthread_t differently).
HS
| |
| Juergen Salk 2005-07-08, 7:49 am |
| * Hendrik Sattler <sattler2000@gmx.de> [050708 02:48]:
Hi Hendrik, all,
thank you for your responses. :-)
> Cited the wrong file for pthread_t definition :-/
> It's
> /usr/include/bits/pthreadtypes.h:typedef unsigned long int pthread_t;
:-)
> Still, no casting is needed
Yes, it's true that no casting is needed here. At least on Linux
where pthread_t is unsigned long int anyway (instead of a struct).
OTOH, I would have expected, that it should not do any harm to cast
pthread_t to unsigned long and vice versa in this case (like it
is handled in the upstream sources). Obviously, this doesn't seem
to be the case any more with gcc 4.0.
> (gcc4 probably wants to tell you that other systems might
> define pthread_t differently).
Yes, maybe. Upstream handles the portability problems with
certain preprocessor directives.
Thanks again for your input, I am going to discuss this issue
with upstream ...
Regards - Juergen
--
GPG A997BA7A | 87FC DA31 5F00 C885 0DC3 E28F BD0D 4B33 A997 BA7A
|
|
|
|
|