Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to modify the "function call" at the preprocessing time or the compile time

1st problem: Is it possible to call a function with some parameters and it gets modify to something else after compilation either at preprocessing time or at compilation time into something like

#define func(a,b) func(a,sizeof(a),b)

Some may think why such a need arose.

Actually I am porting code in windows using visual studio 2010 and there is some functions which are deprecated like strcpy(), strcat(), etc. It says to use strcpy_s() instead.

I know I could have suppressed it using #pragma disable(warning: ) or by providing flags like:

_CRT_NONSTDC_NO_DEPRRECATE
_CRT_SECURE_NO_DEPRECATE
_CRT_SECURE_NO_WARNINGS

But I don't wan't to ignore or suppress them.

I tried to just simply replace the string instead of ignoring by using:

#define strcpy strcpy_s

as in here http://msdn.microsoft.com/en-us/library/td1esda9.aspx I read there would be no mismatch of arguments if I don't provide the second arg.

I mean it should be ok if I use like this:

#define strcpy strcpy_s
strcpy(dest,src);

But its not. It still produce warning.

Definition of strcpy_s is:

errno_t strcpy_s(
   char *strDestination,
   size_t numberOfElements,
   const char *strSource 
);

2nd problem: The first argument is a pointer to a dynamically allocated memory so how can I get the size of the memory pointed by this pointer. Though I read that it's not feasible but there has to be some way(hopefully).

By the way what is _countof(var)?

like image 705
Prabhat Kumar Singh Avatar asked Nov 01 '22 17:11

Prabhat Kumar Singh


1 Answers

These functions are NOT deprecated. Microsoft is trying to induce you to write Microsoft-specific code by falsely claiming they're deprecated even though the ISO WG14 committee (who's responsible for them) has made no such statement.

Defining the three _CRT macro's should be considered as the correct way to put the compiler into a "somewhat closer to the Standard" mode, just like /Za.

like image 190
MSalters Avatar answered Nov 08 '22 05:11

MSalters