Pelles C forum

C language => Beginner questions => Topic started by: Jimg on February 02, 2019, 04:32:10 AM

Title: No support for '__declspec(thread)
Post by: Jimg on February 02, 2019, 04:32:10 AM
I am a total C noob, bear with me---
I'm trying to compile an old Microsoft program (MTTTY).
I get the following error:
 warning #2208: No support for '__declspec(thread)'.
on this line:
 __declspec(thread) static DWORD dwOldStatus = 0;

I assume this is an old form of syntax that has been superseded, ( the program is from 1995), What is the correct way to code this?
Title: Re: No support for '__declspec(thread)
Post by: Jimg on February 02, 2019, 04:41:24 AM
Of course, as soon as I posted I found the an option that solved it.

Project options/compiler/runtime library=multithreaded (LIB).

Sorry for troubling you all.   However, if this is not the correct solution, please let me know :)
Title: Re: No support for '__declspec(thread)
Post by: frankie on February 02, 2019, 05:11:28 PM
Hi Jimg, welcome in PellesC community.
Just a short explanation.
The __declspec() storage class specifier is an MS custom extension supported in PellesC when MS extensions are enabled (see /Ze compiler switch for MS mode enable).
__declspec(thread) specify that the variable will exist only in local thread. To make sense for a local thread storage you should be compiling for a multithreaded application.
If you try to use it in a single threaded environment the compiler issues an error. To enable multithreaded environment you must use the /MT switch (as you made).
Starting with C11 standard revision a new storage class specifier is available: _Thread_local, which is fully equivalent the the MS proprietary __declspec(thread)
Title: Re: No support for '__declspec(thread)
Post by: Jimg on February 02, 2019, 06:32:39 PM
Thanks much for the explanation :)