[Original] Use Visual Studio .NET to write a pure C program prompt

xiaoxiao2021-03-06  104

Use Visual Studio .NET to write a prompt for pure C program

Author: lover_P

The so-called pure C procedure refers to the syntax used by the program (including the executable program or library), strictly abide by the C89 standard, and the library function used is either the standard library function supported by the C89 standard. Either to pure The library function written by the C program.

The above is a non-standard, recursive definition of "Pure C Programs".

Friends using Visual Studio know that the Visual C integrated development environment as a Visual Studio suite does not provide a C language compiler, we can only compile the C program with the C compiler. Although Eckel Bruce believes that compiling the C program can be used to find an implicit error in the program (see "Think In C "), but I insist that this is not a good way: this will only let everyone write those Used a large amount of C characteristics. This procedure is not available. BJNARE STROUSTRUP also believes that C should be an independent of C language, a new programming language; but I think that C should be independent of C , old trees. Language. Therefore, we need a development environment and compiler that can write pure C procedures.

The C compiler in Visual Studio .NET provides us with this function! The C compiler in Visual Studio .NET not only greatly enhances support for C standards, but also compiles pure C procedures through some configurations! In this article I will conduct a brief introduction to their formulation methods, I hope to help those friends who like pure C programming. I also hope that friends who begin a beginner C language program can write beautiful C procedures.

Integrated development environment configuration

First, when the project is established, select the Win32 console application, but must select the "Empty Project" option. This will prevent the Visual Studio wizard from producing unnecessary source files (code) and set some unnecessary compiler options. The specific operation method is shown below:

Select "File" -> "New" -> "Project":

In the New Project dialog, select "Visual C item" in the Project Type Li table box, and select the Win32 Control Project template in the Template list box. Don't forget to enter the name of the project in the Name text box, here I named "PUREC":

After clicking the "OK" button, the Win32 Application Wizard dialog box will pop up, don't worry about "determination":

Initially, when I saw this dialog, I really didn't pay attention to the "Application Settings" option (probably I am too stupid. --_- b). So we want:

Click the "Application Settings" tab, select "Empty Project" in "Additional Options":

This step is the key to the problem. If we don't choose "Empty Project", Visual Studio .NET's wizard will add some source files that support us to support Windows applications (such as "stdafx.h", "stdafx.c", etc.), and will also The compiler makes some settings. Although these settings are very useful for writing a Windows API program, it is very disadvantageous for us to write pure C processes. Therefore, we need to choose "Empty Project."

After clicking the "OK" button, we got an empty project, observed the Solution Explorer list box, we found that there is no guide to our annoying excessive source files. At this time, we need to manually add our source file to the project. Here we add a new source file "purec.c". On the "Source File" folder chart in the Solution Explorer list box, right-click, select Add -> Add New Item: In the "Add New Item" dialog box, select " C file ". And enter the name of the source file in the Name text box. Note that the extension ".c" must be written in the file name, otherwise IDE will automatically add ".cpp" extension to this file:

Next, we have to set the properties of the project. On the Project of the Solution Explorer (here "purec"), right-click and select "Properties" in the pop-up menu. The Properties Page dialog will pop up. Expand the "C / C " node in the tree view on the left, select the "Advanced" node; in the list box appear on the right, "compile to" list item change to "compile to C code (/ TC)" :

Click the "OK" button, OK, is very good.

Configuration of the console option

This topic is a bit ... that ... My intuitive feeling is that people who use the console command line compiler should be shrimp (even if it is not prawn, it has a small shrimp), and the option to the command line should be understood very much. I will not give more ugly, simply, as long as you add / TC options in the command line, you can compile a source file as a pure C code.

test

After such tuning, we have a environment that can write pure C code. If you have no mouth, we have to verify it with a program. Add the following code for our purec.c:

/ * * Model: purec.c * author: lover_p * Date: 2004-6-3 * * TEST The Pure C Environment in vs.net * / struct a {INT I;}; int main () {a a; = 10;} / * end * /

This code is completely correct for C programs, which can be compiled and there is no errors and warnings. However, this is not "pure C program" because in the C standard, when the structure type is used as the variable type, the Struct key must appear in the declaration statement of the variable. Therefore, in our "pure C environment" compiles this code, it will get N more error reports.

Therefore, we have to change the first row of the main () function to a pure C form statement:

Struct a a;

In this way, compile again will be 0 error 0 warning.

to sum up

Finally, this "pure C environment" is just auxiliary, and if you want to learn to write "pure C procedures", you must first carefully learn the standard C language. Don't expect this environment to teach you to write "pure C procedures", just like the above example, only one keyword is missing, so many errors will be obtained in Visual Studio .NET 2003:

E: / Workspace / C / Purec / Purec.c (14): Error C2065: "A": Unconformed Identifier E: / Workspace / C / Purec / Purec.c (14): Error C2146: Syntax Error: Lack ";" (in front of the identifier "a") E: / Workspace / C / purec / purec.c (14): Error C2144: Syntax error: "" in front of "" E: / Workspace / C / purec / purec.c (14): Error C2144: Syntax error: "" in front of "" E: / Workspace / C / Purec / Purec.c (14 : Error C2143: Syntax error: Lack ";" ("in front of" identifier ") E: / Workspace / C / purec / purec.c (14): Error C2065:" A ": Unconflected identifier E : / Workspace / C / purec / purec.c (15): Error C2224: ".i" must have a structure / federation, if you don't know very well on the standard C, face so many errors must be unable to start of. Therefore, language learning is very important, the environment is just an auxiliary function.

Finally, I wish you all a good job in this most NB language.

转载请注明原文地址:https://www.9cbs.com/read-124999.html

New Post(0)