-
March 6th, 2011, 04:04 AM
#1
How to use #define _CRT_SECURE_NO_DEPRECATE?
Hi,
I am trying to use strcpy. I am getting 'deprecated function warning'. One of the posts on this forum suggests to use
#define _CRT_SECURE_NO_DEPRECATE
before stdafx.h
I have done this but still I am getting lot of warnings:
Code:
1>------ Rebuild All started: Project: testCalendar1, Configuration: Debug Win32 ------
1>Deleting intermediate and output files for project 'testCalendar1', configuration 'Debug|Win32'
1>Compiling...
1>stdafx.cpp
1>Compiling...
1>testCalendar1.cpp
1>d:\vcprog\testcalendar1\testcalendar1\testcalendar1.cpp(38) : warning C4996: 'strcpy' was declared deprecated
1> d:\microsoft visual studio 8\vc\include\string.h(73) : see declaration of 'strcpy'
1> Message: 'This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
1>d:\vcprog\testcalendar1\testcalendar1\testcalendar1.cpp(39) : warning C4996: 'strcpy' was declared deprecated
1> d:\microsoft visual studio 8\vc\include\string.h(73) : see declaration of 'strcpy'
1> Message: 'This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
1>Compiling manifest to resources...
1>Linking...
1>LINK : D:\VCPROG\testCalendar1\Debug\testCalendar1.exe not found or not built by the last incremental link; performing full link
1>Embedding manifest...
1>Build log was saved at "file://d:\VCPROG\testCalendar1\testCalendar1\Debug\BuildLog.htm"
1>testCalendar1 - 0 error(s), 2 warning(s)
========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========
My code is as follows:
Code:
#define _CRT_SECURE_NO_DEPRECATE
#include "stdafx.h"
#include "string.h"
int days_in_month[]={0,31,28,31,30,31,30,31,31,30,31,30,31};
char *months[]=
{
" ",
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December"
};
struct Calendar{
char monthName[11];
char DayName[31][3];//worst case
int DayNo[31];
};
Calendar calArr[12]; //12 months
char *DayName[7]={"Mon", "Tue", "Wed", "Thu","Fri", "Sat", "Sun"};
int _tmain(int argc, _TCHAR* argv[])
{
int DayNameIndex;
int month,day;
//_CRT_SECURE_NO_DEPRECATE;
strcpy(calArr[0].DayName[0],"Sat");
strcpy(calArr[0].monthName,"January");
calArr[0].DayNo[0]=1;
DayNameIndex=5;
for ( month = 1; month <= 12; month++ )
{
strcpy_s(calArr[month-1].monthName,months[1]);
//if (month==2) check leap year
for ( day = 1; day <= days_in_month[month]; day++ );
}
Some body plz guide me.
Zulfi.
-
March 6th, 2011, 04:32 AM
#2
Re: How to use #define _CRT_SECURE_NO_DEPRECATE?
Try this one,
#define _CRT_SECURE_NO_WARNINGS
-
March 6th, 2011, 05:50 AM
#3
Re: How to use #define _CRT_SECURE_NO_DEPRECATE?
with both these in the stdafx.h it does now work
#define _CRT_SECURE_NO_DEPRECATE 1
#define _CRT_NONSTDC_NO_DEPRECATE 1
and several other methods
http://social.msdn.microsoft.com/for...-f1de8f7ef291/
-
March 6th, 2011, 08:40 AM
#4
Re: How to use #define _CRT_SECURE_NO_DEPRECATE?
Hi,
Thanks for your attention. I tried both the recipes but still I am getting this warning message.
Kindly guide me.
Zulfi.
-
March 6th, 2011, 09:51 AM
#5
Re: How to use #define _CRT_SECURE_NO_DEPRECATE?
Try adding -D_CRT_SECURE_NO_DEPRECATE to the arguments that you send the compiler.
-
March 6th, 2011, 11:50 AM
#6
Re: How to use #define _CRT_SECURE_NO_DEPRECATE?
Hi,
I have tried the following but still it gives me the same set of warnings:
Code:
#define D_CRT_SECURE_NO_DEPRECATE
#define _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_DEPRECATE 1
#define _CRT_NONSTDC_NO_DEPRECATE 1
#include "stdafx.h"
#include "string.h"
Warnings:
Code:
1>d:\vcprog\testcalendar1\testcalendar1\testcalendar1.cpp(45) : warning C4996: 'strcpy' was declared deprecated
1> d:\microsoft visual studio 8\vc\include\string.h(73) : see declaration of 'strcpy'
1> Message: 'This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
1>d:\vcprog\testcalendar1\testcalendar1\testcalendar1.cpp(46) : warning C4996: 'strcpy' was declared deprecated
1> d:\microsoft visual studio 8\vc\include\string.h(73) : see declaration of 'strcpy'
1> Message: 'This function or variable may be unsafe. Consider using strcpy_s instead. To disable deprecation, use _CRT_SECURE_NO_DEPRECATE. See online help for details.'
1>Linking...
1>Embedding manifest...
1>Build log was saved at "file://d:\VCPROG\testCalendar1\testCalendar1\Debug\BuildLog.htm"
1>testCalendar1 - 0 error(s), 2 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
I still need help on this.
Zulfi.
Last edited by Zulfi Khan2; March 6th, 2011 at 11:51 AM.
Reason: MISSED SOME COMMANDS
-
March 6th, 2011, 12:41 PM
#7
Re: How to use #define _CRT_SECURE_NO_DEPRECATE?
Strange. Just
#define _CRT_SECURE_NO_WARNINGS
should be enough.
I think you still get the messages because
stdafx.cpp
isn't recompiled so the defines don't take effect.
Put
#define _CRT_SECURE_NO_WARNINGS
on top of stdafx.h instead.
---
But before you do that you could try and add this line,
#pragma warning(disable : 4996)
on top of testcalendar1.cpp
Last edited by nuzzle; March 6th, 2011 at 12:54 PM.
-
March 6th, 2011, 01:47 PM
#8
Re: How to use #define _CRT_SECURE_NO_DEPRECATE?
Hi,
I have tried the following:
Code:
// testCalendar1.cpp : Defines the entry point for the console application.
//
#pragma warning(disable : 4996)
#define _CRT_SECURE_NO_WARNINGS
#include "stdafx.h"
#include "string.h"
#include "stdlib.h"
But I am still getting the deprecate message.
Kindly guide me.
I am using VS2005.
Zulfi.
-
March 6th, 2011, 02:11 PM
#9
Re: How to use #define _CRT_SECURE_NO_DEPRECATE?
You should add it to the project settings (C/C++ / Preprocessor / Preprocessor Definitions).
Everything before #include "stdafx.h" is ignored if you have precompiled headers enabled.
-
March 6th, 2011, 05:32 PM
#10
Re: How to use #define _CRT_SECURE_NO_DEPRECATE?
Originally Posted by Zulfi Khan2
But I am still getting the deprecate message.
It wasn't that clear maybe but one of my suggestions was to put,
#define _CRT_SECURE_NO_WARNINGS
inside the actual stdafx.h file (at the top). That should do it.
Last edited by nuzzle; March 6th, 2011 at 05:48 PM.
-
March 7th, 2011, 10:25 AM
#11
Re: How to use #define _CRT_SECURE_NO_DEPRECATE?
Originally Posted by nuzzle
It wasn't that clear maybe but one of my suggestions was to put,
#define _CRT_SECURE_NO_WARNINGS
inside the actual stdafx.h file (at the top). That should do it.
Yes, this is one of the correct ways to handle this.
When using precompiled headers with the Microsoft compiler, it ignores any code in the source file until it finds the include of the precompiled header file. So any of the #defines before the #include "stdafx.h" are just thrown away (ignored).
The other common way to handle this is to add it to the preprocessor definitions in the project, making sure to set it for both debug and release configurations.
-
March 7th, 2011, 12:11 PM
#12
Re: How to use #define _CRT_SECURE_NO_DEPRECATE?
Hi,
I want to thank all my friends for helping me. I have put it on top in the stdafx.h file but still I am getting the same set of warnings.
Code:
#define _CRT_SECURE_NO_WARNINGS
#pragma once
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
#include <stdio.h>
#include <tchar.h>
Kindly guide me. I want to avoid this . Though its not causing any error but for newcomers this can be very much questionable.
Zulfi.
-
March 7th, 2011, 12:24 PM
#13
Re: How to use #define _CRT_SECURE_NO_DEPRECATE?
Hi,
I have done it in preprocessor definitions also. But still I am getting these warnings.
Code:
WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS
-
March 8th, 2011, 02:05 AM
#14
Re: How to use #define _CRT_SECURE_NO_DEPRECATE?
Strange.
Well, I have no further suggestions. There's probably something you do that would be obvious if one could look at the full project.
You'll have to figure it out using the Microsoft documentation,
http://msdn.microsoft.com/en-us/libr...(v=VS.80).aspx
To isolate the problem, create a new project and do nothing but introduce strcpy.
Last edited by nuzzle; March 8th, 2011 at 02:27 AM.
-
July 19th, 2012, 03:12 PM
#15
Re: How to use #define _CRT_SECURE_NO_DEPRECATE?
I know I'm a few years late, but maybe this will help out other people.
Instead of _CRT_SECURE_NO_WARNINGS in the preprocessor, try _CRT_SECURE_NO_DEPRECATE
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|