Difference between __pragma (deprecated) and __declspec (deprecated)

To declare an object deprecated in C / C ++ in Visual Studio, you have three solutions:

  • #pragma deprecated(X)
  • __pragma(deprecated(X))
  • __declspec(deprecated(X))

The first two are the same, except that only the second can be used inside the macro; I set the first for completeness only. The third seems to be most commonly used in the developer community.

I wonder what the difference is between the last two. According to the MSDN documentation here and here, I understand that there is no difference. In this case, it is strange that depending on what you are using, a different warning code is called: C4995 for the case of pragma, C4996 for the case of declspec.

So does anyone know if there really is a difference (some kind of small one), or why these directives do not cause the same warning code?

+7
source share
3 answers

See deprecated (C ++) :

(for Microsoft). Except as noted below, an ad is deprecated and offers the same functionality as an outdated pragma:

  • The obsolete declaration allows you to specify specific forms of function overloads as obsolete, while the pragma form applies to all overloaded forms of the function name.
  • , . .
  • .

#pragma vs. __pragma, . Pragma __Pragma:

__pragma()

Microsoft

__pragma, , #pragma, inline .


, @Deduplicator, ++ 14 [[deprecated]].

7.6.5 [dcl.attr.deprecated]

- deprecated , , - . [: , deprecated , . -end note]

+8

, .

, :

class X
{
   void F1();
   void F2();
}

F1, pragma deprecated, , , F1 .

class X
{
#pragma deprecated(F1)
   void F1();
   void F2();
}

__declspec(deprecated()), , F1. -, #pragma deprecated, , #pragma warning (disable: 4995), , .

class X
{
   __declspec(deprecated("Please use F2")) void F1();
   void F2();
}
+3

Please note that it __declspec(deprecated)does not work with usingads while it [[deprecated]]works.

0
source

All Articles