Prev: VC++ compiler bug?
Next: UTF8 and std::string
From: lists on 1 Jun 2006 07:27 Hi all, while compiling an existing project in the new MSVC 2005 compiler, I received the warning that: : warning C4996: 'localtime' was declared deprecated C:\Program Files\Microsoft Visual Studio 8\VC\include\time.inl(114) : see declaration of 'localtime' Message: 'This function or variable may be unsafe. Consider using localtime_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.' I wasn't aware that localtime was declared deprecated. Is this true? And, if so, is the suggestion of localtime_s standard compliant? If not, what should I use? [This program has to be platform-independent, ISO C++.] Thanks for your help, Matthew. [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Victor Bazarov on 1 Jun 2006 16:59 lists(a)givemefish.com wrote: > while compiling an existing project in the new MSVC 2005 compiler, I > received the warning that: > >> warning C4996: 'localtime' was declared deprecated > C:\Program Files\Microsoft Visual Studio > 8\VC\include\time.inl(114) : see declaration of 'localtime' > Message: 'This function or variable may be unsafe. Consider > using localtime_s instead. To disable deprecation, use > _CRT_SECURE_NO_DEPRECATE. See online help for details.' > > > I wasn't aware that localtime was declared deprecated. Is this true? No. > And, if so, is the suggestion of localtime_s standard compliant? No. > If not, what should I use? [This program has to be > platform-independent, ISO C++.] Keep using 'localtime' until MS comes to its senses (unlikely) or until MS removes it completely from its library implementation (also unlikely). When/If the latter happens, split the code using an ifdef directive. Or simply disable this bogus warning. V -- Please remove capital 'A's when replying by e-mail I do not respond to top-posted replies, please don't ask [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: Bo Persson on 2 Jun 2006 18:36 <lists(a)givemefish.com> skrev i meddelandet news:1149149250.643455.166300(a)y43g2000cwc.googlegroups.com... > Hi all, > > while compiling an existing project in the new MSVC 2005 compiler, I > received the warning that: > > : warning C4996: 'localtime' was declared deprecated > C:\Program Files\Microsoft Visual Studio > 8\VC\include\time.inl(114) : see declaration of 'localtime' > Message: 'This function or variable may be unsafe. Consider > using localtime_s instead. To disable deprecation, use > _CRT_SECURE_NO_DEPRECATE. See online help for details.' > > > I wasn't aware that localtime was declared deprecated. Is this > true? No. There is a proposal to the C standards committee though. Written by Guess Who. http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1172.pdf > > And, if so, is the suggestion of localtime_s standard compliant? Not yet, at least. > > If not, what should I use? [This program has to be > platform-independent, ISO C++.] Then define _CRT_SECURE_NO_DEPRECATE to disable the waring. Bo Persson [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: red floyd on 2 Jun 2006 18:39 lists(a)givemefish.com wrote: > Hi all, > > while compiling an existing project in the new MSVC 2005 compiler, I > received the warning that: > > : warning C4996: 'localtime' was declared deprecated > C:\Program Files\Microsoft Visual Studio > 8\VC\include\time.inl(114) : see declaration of 'localtime' > Message: 'This function or variable may be unsafe. Consider > using localtime_s instead. To disable deprecation, use > _CRT_SECURE_NO_DEPRECATE. See online help for details.' > > > I wasn't aware that localtime was declared deprecated. Is this true? Microsoft has taken it upon itself to deprecate items it considers "unsafe". The ISO committee has not deprecated localtime(), as far as I know. Either disable C4996 or define _CRT_SECURE_NO_DEPRECATE. [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]
From: kanze on 3 Jun 2006 07:53
lists(a)givemefish.com wrote: > while compiling an existing project in the new MSVC 2005 > compiler, I received the warning that: > : warning C4996: 'localtime' was declared deprecated > C:\Program Files\Microsoft Visual Studio > 8\VC\include\time.inl(114) : see declaration of 'localtime' > Message: 'This function or variable may be unsafe. Consider > using localtime_s instead. To disable deprecation, use > _CRT_SECURE_NO_DEPRECATE. See online help for details.' > I wasn't aware that localtime was declared deprecated. Is > this true? Not by the C++ committee, nor by the C committee (I think). Maybe by Microsoft. In fact, the message is misleading; I think Microsoft has admitted this, and plans to change it in the next release. On the other hand, there are cases where localetime might be unsafe -- it cannot be used in multithreaded code, for example. And this fact was recognized and addressed by the C committee. Except for the word "deprecated" itself, the Microsoft warning pretty much corresponds to what the C committee has said. > And, if so, is the suggestion of localtime_s standard compliant? Not in the strictest sense. It is defined in a TR to C -- sort of an official extension. Practically speaking, I would expect most C compilers to gradually move to support it, much as C++ compilers try to support TR1 (except that a lot of C compilers aren't moving, period). If the C compiler supports it, you will likely get it automatically in C++, even if C++ doesn't (yet) recognize the C TR. For the moment, however, most C compilers, much less most C++ compilers, do not support it. (The copy of it that I have access to is dated Sept. 9, 2005, and it is only a draft. So it is very, very new.) > If not, what should I use? [This program has to be > platform-independent, ISO C++.] I'm not sure what the C++ committee's position is with regards to this TR -- given how new it is, I doubt that the C++ committee has even considered it. Practically speaking, you can't use anything in it in portable code. Yet. I might add that I just love the fact that we now have three "standard" functions to do exactly the same thing: localtime (which, however, cannot be used in a multithreaded environment), localtime_r (from Posix, to support multithreaded environments), and localtime_s (the C committee's answer to the problem). -- James Kanze GABI Software Conseils en informatique orient?e objet/ Beratung in objektorientierter Datenverarbeitung 9 place S?mard, 78210 St.-Cyr-l'?cole, France, +33 (0)1 30 23 00 34 [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] |