From owner-freebsd-threads@FreeBSD.ORG Wed May 28 17:34:14 2003 Return-Path: Delivered-To: freebsd-threads@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 8205537B401 for ; Wed, 28 May 2003 17:34:14 -0700 (PDT) Received: from h00609772adf0.ne.client2.attbi.com (h00609772adf0.ne.client2.attbi.com [24.61.43.152]) by mx1.FreeBSD.org (Postfix) with ESMTP id 784B043FA3 for ; Wed, 28 May 2003 17:34:13 -0700 (PDT) (envelope-from rodrigc@h00609772adf0.ne.client2.attbi.com) Received: from h00609772adf0.ne.client2.attbi.com (localhost.ne.attbi.com [127.0.0.1])h4T0YHSr003831 for ; Wed, 28 May 2003 20:34:17 -0400 (EDT) (envelope-from rodrigc@h00609772adf0.ne.client2.attbi.com) Received: (from rodrigc@localhost)h4T0YGtJ003830 for freebsd-threads@freebsd.org; Wed, 28 May 2003 20:34:16 -0400 (EDT) Date: Wed, 28 May 2003 20:34:16 -0400 From: Craig Rodrigues To: freebsd-threads@freebsd.org Message-ID: <20030529003416.GA3712@attbi.com> References: <20030528235120.GA3481@attbi.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.4i Subject: Re: Question about OpenSSL id_function() and pthreads X-BeenThere: freebsd-threads@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Threading on FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 May 2003 00:34:14 -0000 On Wed, May 28, 2003 at 08:07:24PM -0400, Daniel Eischen wrote: > > I have some third party C++ code which tries to implements this function: > > > > static unsigned long > > idFunction() > > { > > #ifdef _WIN32 > > return static_cast(GetCurrentThreadId()); > > #else > > return static_cast(pthread_self()); > > #endif > > } > > > > > > This code does not compile on FreeBSD-CURRENT: > > > > OpenSSLPluginI.cpp: In function `long unsigned int idFunction()': > > OpenSSLPluginI.cpp:151: invalid static_cast from type `pthread*' to type `long > > unsigned int' > > I don't know C++ well (much at all). What does static_cast do? static_cast, unlike C style casts, have restrictions which can result in compile-time errors. The full definition of static_cast is here: http://www.csci.csusb.edu/dick/c++std/cd2/expr.html#expr.static.cast A static_cast *cannot* convert a pointer type to an integral type (unsigned long), and will result in a compile time error. > The error message makes it look as if you are converting > a "pthread" * to "long unsigned int". Don't you just > want "unsigned long" instead? This function needs to return a unique numeric identifier based on a thread. pthread_self() returns a type of pthread_t. On Linux (where this code was written), pthread_t is: typedef unsigned long int pthread_t; So that is why this 3rd party code compiles and works fine on Linux. Obviously, this is not true on FreeBSD. The fact that this code relies on pthread_t being an integer type is bogus, but that's what you get for using 3rd party code. :) So how do I solve this problem on FreeBSD? -- Craig Rodrigues http://home.attbi.com/~rodrigc rodrigc@attbi.com