[CDRIVER-993] Compile error on windows Created: 12/Nov/15  Updated: 08/Dec/15  Resolved: 20/Nov/15

Status: Closed
Project: C Driver
Component/s: None
Affects Version/s: 1.2.1
Fix Version/s: 1.3.0-rc0

Type: Bug Priority: Major - P3
Reporter: Alex Assignee: A. Jesse Jiryu Davis
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows, msvs 2010


Issue Links:
Related
related to CDRIVER-674 Test various MSVC versions Closed

 Description   

error C2664: 'CreateThread' : cannot convert parameter 3 from 'void *' to 'LPTHREAD_START_ROUTINE'
mongo-c-driver\src\mongoc\mongoc-thread-private.h 80

WinApi CreateThread() expects pointer to function that returns DWORD, but linux system cal pthread_create expects pointer to function that returns void *



 Comments   
Comment by Githook User [ 20/Nov/15 ]

Author:

{u'username': u'ajdavis', u'name': u'A. Jesse Jiryu Davis', u'email': u'jesse@mongodb.com'}

Message: CDRIVER-993 fix cast in CreateThread call
Branch: master
https://github.com/mongodb/mongo-c-driver/commit/50f977fc2dbd34bcea7591cd273738bd5bf9624a

Comment by Alex [ 13/Nov/15 ]

Visual studio uses c++ compiler mode for .cpp files and it seems like c++ language have more strict rules of casting, this is why error occurs. void* and DWORD return value types have different sizes so I'm not sure this cast is safe.

Comment by A. Jesse Jiryu Davis [ 13/Nov/15 ]

Thanks, that is useful information. Until we dig a little further, I'm not sure why it matters how you include the driver's headers. Regardless, it seems like we should be casting the function to LPTHREAD_START_ROUTINE, not void *, in the win32 code.

Comment by Alex [ 13/Nov/15 ]

Important note: this error occurs only when using private header in .cpp file(not .c):

// my_src.cpp
#include <mongoc-client-private.h> // includes mongoc-thread-private.h

Comment by A. Jesse Jiryu Davis [ 12/Nov/15 ]

Thanks for the report, we'll check it out.

Generated at Wed Feb 07 21:11:14 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.