The write is better, so turn it over .... If you forget it, you can review it later!
# Pragma indicator
Well, what do you mean today? Yesterday, I talked about how to use the "# pragma" indicator to set connector parameters to export functions. In fact, the "# pragma" function is far more than that, and I have never used most of it, I have used some of the "# pragma" indicators I will talk about today.
1. indicates that the file is only contained once.
In the header file, we generally only need to include it once in the entire project, but if I have multiple. c /. CPP files must contain header files, such as Windows. h, isn't there two declarations? The traditional method to solve this problem is to define a macro with # define at the beginning of the header file, such as in windows. h:
# Ifndef _ WINDOWS _
# DEFINE _ WINDOWS _
Then add # endif to the file to avoid being contained multiple times. But the consequence is that the Code is less readable (personal opinion). VC provides us with another way, that is, to add the following before the file:
# Pragma once"
Is it convenient?
2. Invalid Warning
Sometimes we have to forcibly convert the variables, which leads to a warning from the compiler. Especially in C ++, the type check is stricter than C. Although this does not affect anything, it seems so uncomfortable-I mean to do this, what do you warn me! :) At this time, you will see the Warning type, such as "Warning c4311:" type conversion ":" hhook "to" bool "pointer truncation". Add the following to the front:
# Pragma warning (Disable: 4311)
The compiler has nothing to say :).
3. Specify the database to be connected
For example, if we use wsock32.lib during connection, you can add it to your project without any effort. However, I think it is more convenient to use the # pragma indicator to specify the database to be connected:
# Pragma comment (Lib, "wsock32.lib ")
4. display the compilation message
It is of little use. For example:
# Ifdef _ debug
# Pragma message ("build connection to debug mode ...")
# Endif // _ debug