Podstrony
- Strona startowa
- Linux. .Mandrake.10.Podręcznik.Użytkownika.[eBook.PL] (3)
- (eBook) James, William The Principles of Psychology Vol. II
- (ebook computers) Visual C .NET DeveloperÂ’s Guide
- (Business Ebook) 101 Ebay Auction Secrets (1)
- (Ebook Pl) Fotografia Cyfrowa Poradnik
- Clarke Arthur C Tajemnica Ramy (2)
- Evanovich Janet Po trzecie dla draki (2)
- Swieci W Dziejach Narodu Polski
- Tom Clancy Suma wszystkich strachow t.1
- e95 Blawatska KluczDoTeozofii01
- zanotowane.pl
- doc.pisz.pl
- pdf.pisz.pl
- frenetic.opx.pl
[ Pobierz całość w formacie PDF ]
.The curses example demonstrates thatwithout message forwarding we have to compromise: wrappers that are morelikely reusable for the next project do not function too well in conjunction with anexisting, application-oriented class hierarchy; wrappers that mesh well with ourproblem know too much about it to be generally reusable for dealing with curses.The X11 solution shows the convenience of message forwarding.Wrappersjust about completely hide the internals of X11 and the toolkit widgets.Problem-oriented classes like XButton combine the necessary functionality from thewrappers with the Ic class developed for our calculator.Message forwarding letsclasses like XButton function as if they were descendants of Ic.In this example,message forwarding permits objects to act as if they belonged to two classes atthe same time, but we do not incur the overhead and complexity of multiple inheri-tance as supported in C++.Message forwarding is quite simple to implement.All that needs to be done isto modify the selector generation in the appropriate ooc reports to redirect non-understood selector calls to a new dynamically linked method forward() whichclasses like XButton overwrite to receive and possibly redirect forwarded mes-sages.14.8 ExercisesObviously, wrapping curses into a suitable class hierarchy is an interesting exercisefor character terminal aficionados.Similarly, our X11 calculator experiment can beredone with OSF/Motif or another toolkit.Using accelerators is perhaps not the most natural way to map key presses intoinput to our calculators.One would probably think of action functions first.How-ever, it turns out that while an action function knows the widget it applies to, it hasno reasonable way to get from the widget to our wrapper.Either somebody recom-piles the X toolkit with an extra pointer for user data in the Object instance record,or we have to subclass some toolkit widgets to provide just such a pointer.Giventhe pointer, however, we can create a powerful technology based on action func-tions and our gate().The idea to gate() and wire() was more or less lifted from NeXTSTEP.How-ever, in NeXTSTEP a class can have more than one outlet, i.e., pointer to anotherobject, and during wiring both, the actual outlet and the method to be used at thereceiving end, can be specified.Comparing sections 5.5 and 11.4, we can see that Var should really inherit fromNode and Symbol.Using forward(), we could avoid Val and its subclasses.191___________________________________________________________________________Appendix AANSI-C Programming HintsC was originally defined by Dennis Ritchie in the appendix of [K&R78].The ANSI-Cstandard [ANSI] appeared about ten years later and introduced certain changes andextensions.The differences are summarized very concisely in appendix C of[K&R88].Our style of object-oriented programming with ANSI-C relies on some ofthe extensions.As an aid to classic C programmers, this appendix explains thoseinnovations in ANSI-C which are important for this book.The appendix is certainlynot a definition of the ANSI-C programming language.A.1 Names and ScopeANSI-C specifies that names can have almost arbitrary length.Names starting withan underscore are reserved for libraries, i.e., they should not be used in applicationprograms.Globally defined names can be hidden in a translation unit, i.e., in a source file,by using static:static int f (int x) {.} only visible in source fileint g; visible throughout the programArray names are constant addresses which can be used to initialize pointers even ifan array references itself:struct table { struct table * tp; }v [] = { v, v+1, v+2 };It is not entirely clear how one would code a forward reference to an object whichis still to be hidden in a source file.The following appears to be correct:extern struct x object; forward referencef() { object = value; } using the referencestatic struct x object; hidden definitionA.2 FunctionsANSI-C permits but does not require that the declaration of a function containsparameter declarations right inside the parameter list.If this is done, the function isdeclared together with the types of its parameters.Parameter names may bespecified as part of the function declaration, but this has no bearing on the parame-ter names used in the function definition.double sqrt (); classic versiondouble sqrt (double); ANSI-Cdouble sqrt (double x);.with parameter namesint getpid (void); no parameters, ANSI-CIf an ANSI-C function prototype has been introduced, an ANSI-C compiler will try toconvert argument values into the types declared for the parameters.192 Appendix A ANSI-C Programming Hints___________________________________________________________________________Function definitions may use both variants:double sqrt (double arg) ANSI-C{.}double sqrt (arg) classicdouble arg;{.}There are exact rules for the interplay between ANSI-C and classic prototypes anddefinitions; however, the rules are complicated and error-prone.It is best to stickwith ANSI-C prototypes and definitions, only.With the option -Wall the GNU-C compiler warns about calls to functions thathave not been declared.A.3 Generic Pointers void *Every pointer value can be assigned to a pointer variable with type void * and viceversa, except for const qualifiers.The assignments do not change the pointervalue.Effectively, this turns off type checking in the compiler:int iv [] = { 1, 2, 3 };int * ip = iv; ok, same typevoid * vp = ip; ok, arbitrary tovoid *double * dp = vp; ok,void *to arbitrary%p is used as a format specification for printf() and (theoretically) for scanf() towrite and read pointer values.The corresponding argument type is void * and thusany pointer type:void * vp;printf("%p\n", vp); display valuescanf("%p", & vp); read valueArithmetic operations involving void * are not permitted:void * p, ** pp;p + 1 wrongpp + 1 ok, pointer to pointerThe following picture illustrates this situation:p "pp " " voidA.4 const 193___________________________________________________________________________A.4 constconst is a qualifier indicating that the compiler should not permit an assignment.This is quite different from truly constant values
[ Pobierz całość w formacie PDF ]