I have v1 and v2 versions of my software. v1 uses the registry to save settings, with lots of calls to GetProfileInt, etc. v2 now uses an sqlite db to save settings.
We are currently developing both branches and are merging new features from v1 to the v2 branch. We currently have to remember to update any registry calls to use the new config db and this has been missed a few times.
What I would like is to throw a compiler error if any of the GetProfile... or WriteProfile... functions are used in v2.
We're using C++ in Visual Studio 2010. If there's nothing built in can I use the output from a script to throw a compiler error somehow?
A compile error happens when the compiler reports something wrong with your program, and does not produce a machine-language translation. You will get compile errors.
Compilation error refers to a state when a compiler fails to compile a piece of computer program source code, either due to errors in the code, or, more unusually, due to errors in the compiler itself. A compilation error message often helps programmers debugging the source code.
Compile-time errors are the errors that occurred when we write the wrong syntax. If we write the wrong syntax or semantics of any programming language, then the compile-time errors will be thrown by the compiler. The compiler will not allow to run the program until all the errors are removed from the program.
Syntax errors: Errors that occur when you violate the rules of writing C/C++ syntax are known as syntax errors. This compiler error indicates something that must be fixed before the code can be compiled. All these errors are detected by compiler and thus are known as compile-time errors.
Since this answer is accepted I might as well include the solution the asker actually used:
jacobsee discovered the deprecated pragma
#pragma deprecated(GetProfileInt)
You may be able to declare them as deprecated using __declspec(deprecated)
. It would look like this:
UINT __declspec(deprecated) WINAPI GetProfileInt(
__in LPCTSTR lpAppName,
__in LPCTSTR lpKeyName,
__in INT nDefault
);
You'll have to do so from a header that is included in every translation unit you care about. Doing so will result in a warning any time a translation unit that includes the deprecated declaration uses that function.
If you want a compiler error and if your project doesn't already treat warnings as errors then you'll have to turn that on, and maybe fix all the warnings you've been ignoring. (These are good practices whether you use this solution or not.)
Promoting my comment to an answer:
You can use a macro to redefine them to something that won't compile:
#define GetProfile HAHA_Nice_try_This_will_not_compile!!!
The catch is that you need to make sure that it isn't (legitimately) called outside your code.
(So you should put the macro after all your includes.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With