Can you help me understand why the compiler gives me these error messages? I believe that members of volatile objects are also unstable. I mean here . But this shows that if we have a structure:
struct someStruct { int d; };
And 'p' is defined as follows:
volatile someStruct* volatile* p;
&(*p)->d have the following type 'int * volatile *' instead of 'volatile int * volatile *'. Below is the actual code I'm working on.
Lines (tagged with error 1 and 2) is where the compiler generates error messages:
#include <vector> #include <windows.h> using namespace std; struct ThreadInfo { bool bWaiting = false; bool bWorking = false; }; struct lThreadInfo { ThreadInfo d; lThreadInfo *pNextList = nullptr; } volatile *volatile lThreads(nullptr); thread_local ThreadInfo* currentThr(nullptr); void CreateThread_(void (*pFunc)(ThreadInfo*)) { volatile lThreadInfo* volatile* p = &lThreads; for(; *p; p = &(*p)->pNextList); //**//error 1!** *p = new lThreadInfo; CreateThread( nullptr, // default security attributes 0, // use default stack size (long unsigned int (*)(void*))pFunc, // thread function name &(*p)->d, // argument to thread function **//error 2!** 0, // use default creation flags nullptr); }
The error messages are as follows:
error 1: invalid conversion from 'lThreadInfo* volatile*' to 'volatile lThreadInfo* volatile*' [-fpermissive] error 2: invalid conversion from 'volatile void*' to 'LPVOID {aka void*}' [-fpermissive]
Note I know that volatility has nothing to do with thread safety, so I donβt need to say that. Note 1 . I am using the mingw64 compiler for Windows.
source share