This is the mail archive of the
pthreads-win32@sourceware.org
mailing list for the pthreas-win32 project.
Re: error C2678 and C2440
- From: Peter Slacik <peter dot slacik at tatramed dot sk>
- To: satish <satishjadav at gmail dot com>
- Cc: pthreads-win32 <pthreads-win32 at sourceware dot org>
- Date: Fri, 14 Dec 2007 14:47:15 +0100
- Subject: Re: error C2678 and C2440
- References: <57a6149b0712140110o229cf003h196271eaeb8b7c76@mail.gmail.com>
Hi,
(shortened)
satish wrote:
> Hi,
> I am porting my multi threading(using pthread) Linux project to
> windows. The compiler is MS VC++ 2005.
>
> The project compilation is almost done but I am getting few errors
> related to pthread.
>
> A.:- Have a look on following code,
> ----------------------------------------------------------------
> typedef struct {
> pthread_t id;
> } THREADLIST;
>
> THREADLIST threads[MAXTHREADS];
>
> 1283 pthread_t self = pthread_self();
> 1286 if (threads[i].flags != THREAD_UNUSED && threads[i].id == self) ----------------------------------------------------------------
>
> The error, I am getting is,
>
> 1>main.cpp(1286) : error C2678: binary '==' : no operator found which
> takes a left-hand operand of type 'pthread_t' (or there is no
> acceptable conversion)
> 1> c:\program files\microsoft visual studio
> 8\vc\platformsdk\include\guiddef.h(192): could be 'int operator
> ==(const GUID &,const GUID &)'
> 1> while trying to match the argument list '(pthread_t, pthread_t)'
>
>
IIRC you've to use int pthread_equal(pthread_t thread1, pthread_t
thread2) for the comparison. Because pthread_t is defined as:
typedef struct {
void * p; /* Pointer to actual object */
unsigned int x; /* Extra information - reuse count etc */
} ptw32_handle_t;
typedef ptw32_handle_t pthread_t;
> B.:- Another piece of code on which I am getting error is,
> ----------------------------------------------------------------
> 52 int ret;
> 53 ret = pthread_self();
> ----------------------------------------------------------------
> Here, it gives error like,
>
> 1>main.cpp(53) : error C2440: '=' : cannot convert from 'pthread_t' to 'int'
>
>
Because of pthread_self()'s return value definition:
pthread_t pthread_self (void);
Already in your previous example, you've used
1283 pthread_t self = pthread_self();
This is the way to go.
> Can you please tell me the reason behind these errors?
> I will be very thankful to you.
>
> Regards
> Satish
>
With regards
Peter
PS: I'm resending this, my original email was not plain text, sorry.