For Programmers: Free Programming Magazines  


Home > Archive > VC STL > January 2006 > Re: @deprecated in C++: anything better than #pragma message( "War









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: @deprecated in C++: anything better than #pragma message( "War
ultranet

2006-01-09, 11:10 pm



"Igor Tandetnik" wrote:

> See #pragma deprecated, __declspec(deprecated).
> --

Is this a 7.0, 7.1, or 8.0 feature? I'm not seeing these options in VC 6.0.
It's better than nothing, but if there's something to imitate this in 6.0,
please let me know.
ultranet

2006-01-09, 11:10 pm



"ultranet" wrote:

>
>
> "Igor Tandetnik" wrote:
>
> Is this a 7.0, 7.1, or 8.0 feature? I'm not seeing these options in VC 6.0.
> It's better than nothing, but if there's something to imitate this in 6.0,
> please let me know.

In 6.0, this causes:
: warning C4068: unknown pragma
ultranet

2006-01-09, 11:10 pm



"ultranet" wrote:
> In 6.0, this causes:
> : warning C4068: unknown pragma

The best i could come up w/ in 6.0 was a conditional pragma for after
compiler upgrade:
/**
* @deprecated Use <tt>myfunction</tt> instead, due to <tt>Date</tt> type not
* being characterized by a time zone and thus being unsafe. Usage of
this function
* could result in time being off by a multiple of UTC offset.
*/
#pragma warning( disable: 4068)
#pragma deprecated(GetPersonnelInfoByDate)
#pragma warning( default: 4068)
_DLL_IMPORT_ (BOOL, myfunction (double ));
Ulrich Eckhardt

2006-01-10, 4:16 am

ultranet wrote:
> The best i could come up w/ in 6.0 was a conditional pragma for after
> compiler upgrade:

[...]
> #pragma warning( disable: 4068)
> #pragma deprecated(GetPersonnelInfoByDate)
> #pragma warning( default: 4068)
> _DLL_IMPORT_ (BOOL, myfunction (double ));


Please, for the sake of your users never use #pragma warning( default:...),
always use the push and pop functions provided for that.

Else, I recently used this:

#if _MSC_VER <= 1300
# define MYLIB_DEPRECATED __declspec(deprecated)
#else
// not supported before MSC12 (VC6/eVC4)
# define MYLIB_DEPRECATED
#endif

BOOL MYLIB_DEPRECATED myfunction(double);

Uli

ultranet

2006-01-10, 7:24 pm



"Ulrich Eckhardt" wrote:

> #if _MSC_VER <= 1300
> # define MYLIB_DEPRECATED __declspec(deprecated)
> #else
> // not supported before MSC12 (VC6/eVC4)
> # define MYLIB_DEPRECATED
> #endif
>
> BOOL MYLIB_DEPRECATED myfunction(double);


I'd prefer this, but can't figure out how to escape #pragma in #define:

#if (_MSC_VER >= 1200)
#define DEPRECATED(identifier) \#pragma deprecated(identifier) // VC 7.0+
#else
#define DEPRECATED(identifier)
#endif
ultranet

2006-01-10, 7:24 pm



"ultranet" wrote:

>
>
> "Ulrich Eckhardt" wrote:
>
>
> I'd prefer this, but can't figure out how to escape #pragma in #define:
>
> #if (_MSC_VER >= 1200)
> #define DEPRECATED(identifier) \#pragma deprecated(identifier) // VC 7.0+
> #else
> #define DEPRECATED(identifier)
> #endif

i meant:
#if (_MSC_VER >= 1300)
#define DEPRECATED(identifier) \#pragma deprecated(identifier) // VC 7.0+
#else
#define DEPRECATED(identifier)
#endif
Igor Tandetnik

2006-01-10, 7:24 pm

ultranet <ultranet@discussions.microsoft.com> wrote:
> I'd prefer this, but can't figure out how to escape #pragma in
> #define:
>
> #if (_MSC_VER >= 1200)
> #define DEPRECATED(identifier) \#pragma deprecated(identifier) // VC
> 7.0+ #else
> #define DEPRECATED(identifier)
> #endif


You can't. A macro expansion is never treated as a preprocessor
directive, even if it resembles one.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


ultranet

2006-01-10, 7:24 pm

"Igor Tandetnik" wrote:

> You can't. A macro expansion is never treated as a preprocessor
> directive, even if it resembles one.

Wow, that means i can't mark something like the following as deprecated at
all:
_DLL_IMPORT_ (BOOL, MyFunction(double Id, Info *info));

For instance, the following doesn't generate any errors on VC 6, which means
deprecated attribute is simply ignored:
_DLL_IMPORT_ (__declspec(deprecated) BOOL, MyFunction (double Id, Info
*info));

Looks like i don't have a choice but to use my original, replacing #pragma
disable w/ push, and default w/ pop.
ultranet

2006-01-10, 7:24 pm

"ultranet" wrote:

> "Igor Tandetnik" wrote:
>
> Wow, that means i can't mark something like the following as deprecated at
> all:
> _DLL_IMPORT_ (BOOL, MyFunction(double Id, Info *info));
>
> For instance, the following doesn't generate any errors on VC 6, which means
> deprecated attribute is simply ignored:
> _DLL_IMPORT_ (__declspec(deprecated) BOOL, MyFunction (double Id, Info
> *info));
>
> Looks like i don't have a choice but to use my original, replacing #pragma
> disable w/ push, and default w/ pop.


Please ignore my last post: i wasn't getting an error because i was building
the project that exports it, while it's declared deprecated in import
declaration. :)
ultranet

2006-01-10, 7:24 pm

I'm going to use:
DEPRECATED _DLL_IMPORT_ (BOOL, MyFunction (double Id, Info *info));

This expands into:
__declspec (deprecated) extern __declspec (dllimport) BOOL __stdcall
MyFunction (double Id, Info *info);

I expected this to be OK, but would appreciate if someone w/ VC 7.0+ could
confirm.

P.S. Basically, i'm a tiny bit curious about extern being preceded by
__declspec.

Thanks.
Igor Tandetnik

2006-01-10, 7:24 pm

ultranet <ultranet@discussions.microsoft.com> wrote:
> "Igor Tandetnik" wrote:
>
> Wow, that means i can't mark something like the following as
> deprecated at all:
> _DLL_IMPORT_ (BOOL, MyFunction(double Id, Info *info));


#pragma deprecate is a preprocessor directive. A macro cannot produce
one.

__declspec(deprecated) is a declarator. It's not handled by the
preprocessor, but by the compiler. A macro can generate it. Ulrich
Eckhardt shows an example a couple posts above.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


Igor Tandetnik

2006-01-10, 7:24 pm

ultranet <ultranet@discussions.microsoft.com> wrote:
> I'm going to use:
> DEPRECATED _DLL_IMPORT_ (BOOL, MyFunction (double Id, Info *info));
>
> This expands into:
> __declspec (deprecated) extern __declspec (dllimport) BOOL __stdcall
> MyFunction (double Id, Info *info);
>
> I expected this to be OK, but would appreciate if someone w/ VC 7.0+
> could confirm.
>
> P.S. Basically, i'm a tiny bit curious about extern being preceded by
> __declspec.


As far as I know, extern keyword does not do anything useful when
applied to function declaration. I believe you can safely drop it.

__declspec declarators can go before or after return type. You might
prefer declaring your functions in a more natural way, for example

DEPRECATED BOOL _DLL_IMPORT_ MyFunction(double Id, Info *info);

where _DLL_IMPORT_ would exand to

__declspec(dllimport) __stdcall

Also note that any identifier that begins with the underscore followed
by a capital letter is reserved for implementation. You should not,
strictly speaking, use _DLL_IMPORT_ name. The common practice is to use
<ProjectName>API - e.g. WINBASEAPI, WINCRYPT32API
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com