Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

warning: cast between incompatible function types from FARPROC_ to gettickcount64_t #225

Closed
kivadiu opened this issue Jul 30, 2018 · 8 comments

Comments

@kivadiu
Copy link
Contributor

kivadiu commented Jul 30, 2018

While building 1.68.0 beta 1 on x86_64 cross-compiling to Windows 32 bits with mingw-w64 + g++ 8.2.0, I get the following warning:

"i686-w64-mingw32-g++-8.2.0"   -I/softs/win32-mingw-8.2.0/release/iconv/include -I/softs/win32-mingw-8.2.0/release/gettext/include -I/softs/win32-mingw-8.2.0/release/bzip2/include -I/softs/win32-mingw-8.2.0/release/zlib/include -I/softs/win32-mingw-8.2.0/release/jpeg-turbo/include -I/softs/win32-mingw-8.2.0/release/xz/include -I/softs/win32-mingw-8.2.0/release/tiff/include -I/softs/win32-mingw-8.2.0/release/png/include -std=c++14 -O2 -DNDEBUG -m32 -mthreads -O3 -finline-functions -Wno-inline -Wall -pedantic -march=i686 -Wextra -Wno-long-long -Wno-unused-parameter -Wunused-function -pedantic -DBOOST_ALL_NO_LIB=1 -DBOOST_ASIO_NO_DEPRECATED -DBOOST_CHRONO_STATIC_LINK=1 -DBOOST_FILESYSTEM_NO_DEPRECATED -DBOOST_LOG_WITHOUT_EVENT_LOG -DBOOST_SYSTEM_NO_DEPRECATED -DBOOST_SYSTEM_STATIC_LINK=1 -DBOOST_THREAD_BUILD_LIB=1 -DBOOST_THREAD_USES_CHRONO -DBOOST_THREAD_WIN32 -DBOOST_USE_WINDOWS_H -DNDEBUG -DWIN32_LEAN_AND_MEAN  -I"." -c -o "bin.v2/libs/thread/build/gcc-8.2.0/release/link-static/target-os-windows/threadapi-win32/threading-multi/win32/thread_primitives.o" "libs/thread/src/win32/thread_primitives.cpp"
libs/thread/src/win32/thread_primitives.cpp: In function 'boost::detail::win32::ticks_type boost::detail::win32::{anonymous}::get_tick_count_init()':
libs/thread/src/win32/thread_primitives.cpp:97:120: warning: cast between incompatible function types from 'boost::winapi::FARPROC_' {aka 'int (__attribute__((stdcall)) *)()'} to 'boost::detail::win32::detail::gettickcount64_t' {aka 'long long unsigned int (__attribute__((stdcall)) *)()'} [-Wcast-function-type]
             (boost::detail::win32::detail::gettickcount64_t)boost::winapi::get_proc_address(hKernel32, "GetTickCount64");
                                                                                                                        ^

@viboes
Copy link
Collaborator

viboes commented Aug 6, 2018

Hi, thanks for reporting this.

It seems there is yet an issue when we moved to winapi.
@Lastique, do you have any idea of c-what can be done?

@Lastique
Copy link
Member

Lastique commented Aug 6, 2018

The only thing I can suggest is to silence or work around the warning. The code is correct, AFAICS, this is the intended usage pattern of GetProcAddress, which indeed requires a cast between potentially different types of function pointers.

@viboes
Copy link
Collaborator

viboes commented Aug 6, 2018

It is weird to cast between "potentially different types of function pointers", isn't it?
What could be the expected result of such a kind of casts?

@Lastique
Copy link
Member

Lastique commented Aug 6, 2018

Not so weird, not really. GetProcAddress returns a pointer to some function. It can return pointers to different functions, so it has to return something that is suitable to store any pointer to function. Microsoft chose FARPROC, which is int (WINAPI *)() on 32-bit Windows. The user is supposed to know the signature of the function he requests and perform a cast (which is a nop on this platform). The result is a pointer to function with the required signature, which is bitwise equal to what GetProcAddress returned.

This may not be a well defined standard C++, but, well, that's now 95% of system programming works.

@kivadiu
Copy link
Contributor Author

kivadiu commented Aug 6, 2018

So it's really harmless. I'm happy to hear that.

@viboes viboes removed the bug label Aug 6, 2018
@viboes
Copy link
Collaborator

viboes commented Aug 6, 2018

Ok, I would accept a PR that silent this warning.

Sorry, I don't have a Windows platform to test it.

kivadiu added a commit to kivadiu/thread that referenced this issue Aug 8, 2018
…to gettickcount64_t

On Windows, GetProcAddress must be cast to something useful which
generates a warning with gcc. This patch silents the warning.

Fixes issue boostorg#225
@kivadiu
Copy link
Contributor Author

kivadiu commented Aug 9, 2018

Any idea why PR #227 failed some tests in appveyor?
It seems completely unrelated to my patch.

kivadiu added a commit to kivadiu/thread that referenced this issue Aug 9, 2018
…to gettickcount64_t

On Windows, GetProcAddress must be cast to something useful which
generates a warning with gcc. This patch silents the warning.

Fixes issue boostorg#225
@viboes viboes added fixed and removed PR welcome labels Sep 6, 2018
@viboes
Copy link
Collaborator

viboes commented Sep 6, 2018

See #227

@viboes viboes closed this as completed Sep 6, 2018
sumogr added a commit to sumogr/monero that referenced this issue Apr 4, 2020
I ll spam a bit by pushing a couple of prs fixing warnings on mingw builds. I wanted to push in one but it is better if i do it separately for you to check their validity better

1st warning line 155 - GCC is warning that adding const to the static cast type doesn't do anything. True. Remove it.

2nd - 3rd same warnings lines 333, 386 - GetProcAddress returns a pointer to some function. It can return pointers to different functions, so it has to return something that is suitable to store any pointer to function. Microsoft chose FARPROC, which is int (WINAPI *)() on 32-bit Windows. The user is supposed to know the signature of the function he requests and perform a cast (which is a nop on this platform). The result is a pointer to function with the required signature, which is bitwise equal to what GetProcAddress returned. However, gcc >= 8 warns about that and it shouldnt. There is nothing to fix here so silence the warning explicitly.
Related to this
boostorg/thread#225
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants