为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

计算机C语言专业外文翻译

2017-09-21 10页 doc 40KB 42阅读

用户头像

is_637320

暂无简介

举报
计算机C语言专业外文翻译计算机C语言专业外文翻译 C A History of C C and CThe C programming language was created in the spirit of the C and C programminglanguages. This accounts for its powerful features and easy learning curve. The same cant besaid for C and C but because C was created from the groun...
计算机C语言专业外文翻译
计算机C语言专业外文翻译 C A History of C C and CThe C programming language was created in the spirit of the C and C programminglanguages. This accounts for its powerful features and easy learning curve. The same cant besaid for C and C but because C was created from the ground up Microsoft took theliberty of removing some of the more burdensome features — such as pointers. This sectiontakes a look at the C and C languages tracing their evolution into C.The C programming language was originally designed for use on the UNIX operating system.C was used to create many UNIX applications including a C compiler and was eventuallyused to write UNIX itself. Its widespread acceptance in the academic arena expanded toinclude the commercial world and software vendors such as Microsoft and Borland releasedC compilers for personal computers. The original Windows API was designed to work withWindows code written in C and the latest set of the core Windows operating system APIsremain compatible with C to this day.From a design standpoint C lacked a detail that other languages such as Smalltalk had alreadyembraced: the concept of an object. Youll learn more about objects in Chapter 8 quot WritingObject-Oriented Code.quot For now think of an object as a collection of data and a set ofoperations that can be performed on that data. Object-style coding could be accomplishedusing C but the notion of an object was not enforced by the language. If you wanted tostructure your code to resemble an object fine. If you didnt fine. C really didnt care. Objectswerent an inherent part of the language so many people didnt pay much attention to thisprogramming paradigm.After the notion of object-oriented development began to gain acceptance it became clear thatC needed to be refined to embrace this new way of thinking about code. C was created toembody this refinement. It was designed to be backwardly compatible with C such that all Cprograms would also be C programs and could be compiled with a C compiler. Themajor addition to the C language was support for this new object concept. The Clanguage added support for classes which are quottemplatesquot of objects and enabled an entiregeneration of C programmers to think in terms of objects and their behavior.The C language is an improvement over C but it still has some disadvantages. C and Ccan be hard to get a handle on. Unlike easy-to-use languages like Visual Basic C and C arevery quotlow levelquot and require you to do a lot of coding to make your application run well. Youhave to write your own code to handle issues such as memory management and errorchecking. C and C can result in very powerful applications but you need to ensure thatyour code works well. One bug can make the entire application crash or behave unexpectedly.Because of the C design goal of retaining backward compatibility with C C was unableto break away from the low level nature of C.Microsoft designed C to retain much of the syntax of C and C. Developers who arefamiliar with those languages can pick up C code and begin coding relatively quickly. Thebig advantage to C however is that its designers chose not to make it backwardlycompatible with C and C. While this may seem like a bad deal its actually good news. Celiminates the things that makes C and C difficult to work with. Because all C code is alsoC code C had to retain all of the original quirks and deficiencies found in C. C isstarting with a clean slate and without any compatibility requirements so it can retain thestrengths of its predecessors and discard the weaknesses that made life hard for C and Cprogrammers.Introducing CC the new language introduced in the .NET Framework is derived from C. However Cis a modern objected-oriented from the ground up type-safe language.Language featuresThe following sections take a quick look at some of the features of the C language. If someof these concepts dont sound familiar to you dont worry. All of them are covered in detail inlater chapters.ClassesAll code and data in C must be enclosed in a class. You cant define a variable outside of aclass and you cant write any code thats not in a class. Classes can have constructors whichexecute when an object of the class is created and a destructor which executes when anobject of the class is destroyed. Classes support single inheritance and all classes ultimatelyderive from a base class called object. C supports versioning techniques to help your classesevolve over time while maintaining compatibility with code that uses earlier versions of yourclasses.As an example take a look at a class called Family. This class contains the two static fieldsthat hold the first and last name of a family member as well as a method that returns the fullname of the family member.class Class1public string FirstNamepublic string LastNamepublic string FullNamereturn FirstName LastNameNote Single inheritance means that a C class can inherit from only one base class.C enables you to group your classes into a collection of classes called a namespace.Namespaces have names and can help organize collections of classes into logical groupings.As you begin to learn C it becomes apparent that all namespaces relevant to the .NETFramework begin with System. Microsoft has also chosen to include some classes that aid inbackwards compatibility and API access. These classes are contained within the Microsoftnamespace.Data typesC lets you work with two types of data: value types and reference types. Value types holdactual values. Reference types hold references to values stored elsewhere in memory.Primitive types such as char int and float as well as enumerated values and structures arevalue types. Reference types hold variables that deal with objects and arrays. C comes withpredefined reference types object and string as well as predefined value types sbyte shortint long byte ushort uint ulong float double bool char and decimal. You can also defineyour own value and reference types in your code. All value and reference types ultimatelyderive from a base type called object.C allows you to convert a value of one type into a value of another type. You can work withboth implicit conversions and explicit conversions. Implicit conversions always succeed anddont lose any information for example you can convert an int to a long without losing anydata because a long is larger than an int. Explicit conversions may cause you to lose data forexample converting a long into an int may result in a loss of data because a long can holdlarger values than an int. You must write a cast operator into your code to make an explicitconversion happen.Cross-ReferenceRefer to Chapter 3 quotWorking with Variablesquot for more informationabout implicit and explicit conversions.You can work with both one-dimensional and multidimensional arrays in C.Multidimensional arrays can be rectangular in which each of the arrays has the samedimensions or jagged in which each of the arrays has different dimensions.Classes and structures can have data members called properties and fields. Fields arevariables that are associated with the enclosing class or structure. You may define a structurecalled Employee for example that has a field called Name. If you define a variable of typeEmployee called CurrentEmployee you can retrieve the employees name by writingCurrentEmployee.Name. Properties are like fields but enable you to write code to specifywhat should happen when code accesses the value. If the employees name must be read froma database for example you can write code that says quotwhen someone asks for the value ofthe Name property read the name from the database and return the name as a string.quotFunctionsA function is a callable piece of code that may or may not return a value to the code thatoriginally called it. An example of a function would be the FullName function shown earlierin this chapter in the Family class. A function is generally associated to pieces of code thatreturn information whereas a method generally does not return information. For our purposeshowever we generalize and refer to them both as functions.Functions can have four kinds of parameters: Input parameters have values that are sent into the function but the function cannotchange those values. Output parameters have no value when they are sent into the function but the functioncan give them a value and send the value back to the caller. Reference parameters pass in a reference to another value. They have a value comingin to the function and that value can be changed inside the function. Params parameters define a variable number of arguments in a list.C and the CLR work together to provide automatic memory management. You dont need towrite code that says quotallocate enough memory for an integerquot or quotfree the memory that thisobject was using.quot The CLR monitors your memory usage and automatically retrieves morewhen you need it. It also frees memory automatically when it detects that it is no longer beingused this is also known as Garbage Collection.C provides a variety of operators that enable you to write mathematical and bitwiseexpressions. Many but not all of these operators can be redefined enabling you to changehow the operators work.C supports a long list of statements that enable you to define various execution paths withinyour code. Flow control statements that use keywords such as if switch while for break andcontinue enable your code to branch off into different paths depending on the values of yourvariables.Classes can contain code and data. Each class member has something called an accessibilityscope which defines the members visibility to other objects. C supports public protectedinternal protected internal and private accessibility scopes.VariablesVariables can be defined as constants. Constants have values that cannot change during theexecution of your code. The value of pi for instance is a good example of a constant becauseits value wont be changing as your code runs. Enum type declarations specify a type namefor a related group of constants. For example you could define an enum of Planets withvalues of Mercury Venus Earth Mars Jupiter Saturn Uranus Neptune and Pluto and usethose names in your code. Using the enum names in code makes code more readable than ifyou used a number to represent each planet.C provides a built-in mechanism for defining and handling events. If you write a class thatperforms a lengthy operation you may want to invoke an event when the operation iscompleted. Clients can subscribe to that event and catch the event in their code which enablesthem to be notified when you have completed your lengthy operation. The event handlingmechanism in C uses delegates which are variables that reference a function.Note An event handler is a procedure in your code that determines the actions to beperformed when an event occurs such as the user clicking a button.If your class holds a set of values clients may want to access the values as if your class werean array. You can write a piece of code called an indexer to enable your class to be accessedas if it were an array. Suppose you write a class called Rainbow for example that contains aset of the colors in the rainbow. Callers may want to write MyRainbow0 to retrieve the firstcolor in the rainbow. You can write an indexer into your Rainbow class to define what shouldbe returned when the caller accesses your class as if it were an array of values.InterfacesC supports interfaces which are groups of properties methods and events that specify a setof functionality. C classes can implement interfaces which tells users that the class supportsthe set of functionality documented by the interface. You can develop implementations ofinterfaces without interfering with any existing code which minimizes compatibilityproblems. Once an interface has been published it cannot be changed but it can evolvethrough inheritance. C classes can implement many interfaces although the classes can onlyinherit from a single base class.Lets look at a real-world example that would benefit from interfaces to illustrate its extremelypositive role in C. Many applications available today support add-ins. Assume that you havecreated a code editor for writing applications. This code editor when executed has thecapability to load add-ins. To do this the add-in must follow a few rules. The DLL add-inmust export a function called CEEntry and the name of the DLL must begin with CEd. Whenwe run our code editor it scans its working directory for all DLLs that begin with CEd. Whenit finds one it is loaded and then it uses the GetProcAddress to locate the CEEntry functionwithin the DLL thus verifying that you followed all the rules necessary to create an add-in.This method of creating and loading add-ins is very burdensome because it burdens the codeeditor with more verification duties than necessary. If an interface were used in this instanceyour add-in DLL could have implemented an interface thus guaranteeing that all necessarymethods properties and events were present with the DLL itself and functioning asdocumentation specified.AttributesAttributes declare additional information about your class to the CLR. In the past if youwanted to make your class self-describing you had to take a disconnected approach in whichthe documentation was stored in external files such as IDL or even HTML files. Attributessolve this problem by enabling you the developer to bind information to classes — any kindof information. For example you can use an attribute to embed documentation informationinto a class. Attributes can also be used to bind runtime information to a class defining how itshould act when used. The possibilities are endless which is why Microsoft includes manypredefined attributes within the .NET Framework.Compiling CRunning your C code through the C compiler produces two important pieces ofinformation: code and metadata. The following sections describe these two items and thenfinish up by examining the binary building block of .NET code: the assembly.Microsoft Intermediate Language MSILThe code that is output by the C compiler is written in a language called MicrosoftIntermediate Language or MSIL. MSIL is made up of a specific set of instructions thatspecify how your code should be executed. It contains instructions for operations such asvariable initialization calling object methods and error handling just to name a few. C isnot the only language in which source code changes into MSIL during the compilationprocess. All .NET-compatible languages including Visual Basic .NET and Managed Cproduce MSIL when their source code is compiled. Because all of the .NET languagescompile to the same MSIL instruction set and because all of the .NET languages use the sameruntime code from different languages and different compilers can work together easily.MSIL is not a specific instruction set for a physical CPU. It knows nothing about the CPU inyour machine and your machine knows nothing about MSIL. How then does your .NETcode run at all if your CPU cant read MSIL The answer is that the MSIL code is turned intoCPU-specific code when the code is run for the first time. This process is called quotjust-in-timequotcompilation or JIT. The job of a JIT compiler is to translate your generic MSIL code intomachine code that can be executed by your CPU.You may be wondering about what seems like an extra step in the process. Why generateMSIL when a compiler could generate CPU-specific code directly After all compilers havealways done this in the past. There are a couple of reasons for this. First MSIL enables yourcompiled code to be easily moved to different hardware. Suppose youve written some Ccode and youd like it to run on both your desktop and a handheld device. Its very likely thatthose two devices have differ.
/
本文档为【计算机C语言专业外文翻译】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索