Path: utzoo!mnetor!uunet!lll-winken!lll-tis!ames!pacbell!att-ih!ihnp4!ihlpf!nevin1 From: nevin1@ihlpf.ATT.COM (00704a-Liber) Newsgroups: comp.lang.modula2 Subject: Re: M2 IO Message-ID: <4551@ihlpf.ATT.COM> Date: 27 Apr 88 01:35:36 GMT References: <8804170859.AA18926@klaus.olsen.uucp> Reply-To: nevin1@ihlpf.UUCP (00704a-Liber,N.J.) Organization: AT&T Bell Laboratories - Naperville, Illinois Lines: 80 In article <8804170859.AA18926@klaus.olsen.uucp> Info-Modula2 Distribution List writes: |In reply to Nevin J. Liber's message: |> Yes, but when you use printf() you have to declare the type of each |> variable in the format string. If you use C++ streams the compiler does |> this for you. I know of no other way to do something like this with a |> variable number of arguments. |I repeate the question: Does C++ provide format |specifiers, e.g. "%-.10s", "%10.5e", "%04x", etc.? I find these very |convenient when doing anything more than debugging output. Yes it does (as a matter of fact, the C++ Book has a whole chapter devoted to streams). There are some special-case functions defined such as for outputting hex, and a general-case function called form() which allows all the formats of printf(). |So you are trying to tell me that if we had overloading in Modula-2, we |wouldn't be able to overload the words "OR", "AND", "NOT", "IN", etc. |because "words" lead to unreadable code? Some people might argue that: | e := a AND b AND c OR d; |leads to unreadable code. For that matter, others might argue that: | if ((*timer && ((*timer)->tv_sec == 0) && ((*timer)->tv_usec == 0)) || | (gfx->gfx_flags & GFX_RESTART)) { |is unreadable. I think readability is in the eyes of the beholder. Overloading already-defined operators ("AND" is considered an operator in M2) is fine, but you may run into some problems if you try to allow new infix operators to be defined (order of precedence, associativity, redefining it for the built-in types, etc.). |We have established that C++ only allows infix operator overloading. |The next question is: Does C++ allow procedure name overloading (a la |Ada) or default parameters (a la Mesa)? In other words, do I need |to name my procedures differently even though they perform essentially |the same functions (e.g. could "printf", "fprintf", and "sprintf" |all be called via the same name)? Both procedure overloading and default parameters are allowed (and are usually the norm). |> Learn about the language before you criticize it!!! |You are right. Please correct me where I deviate. I am interested |in C++, but I haven't had a chance to use it. Sorry I got so mad. It's just that most people usually criticize without trying to learn about the subject they are criticizing. Please don't hold it against me. |>>Note the advantage of M2 generics over C++ is that you not only get |>>the pointer, but you have the option of pass-by-value or pass-by-reference. |>>Another important feature is that M2 generics pass the size of the type |>>which can used in a limited form of dynamic type checking. | |> C++ has both call-by-reference and call-by-value (the former being |> new with respect to C and the latter being the same as passing an |> address in C), as well as a way to have automatic dynamic type checking |> (if you want the additional runtime overhead that's required). |I wasn't speaking in terms of ordinary parameters. My point was with |respect to generics, that is, is there an equivalent of ARRAY OF SYSTEM.BYTE |in C++? It might be called "refany" or something of that ilk. From my |understanding of C++, I believe generics are handled only by pointers |(a la Modula-2 SYSTEM.ADDRESS). If this is incorrect, could you do a |quick example and send it to me (or to this list)? I don't know how generics in M2 work, so I can't really say. In C++, overloaded functions are selected according to the type of a pointer to an object. You can direct the C++ translator to store a pointer to the function that is appropriate for that object with the object itself, so that this function selection is dun at run-time. These are called virtual functions. [The above has been paraphrased from my C++ class notes.] Is this what you are looking for? Hope this helps, -- _ __ NEVIN J. LIBER ..!ihnp4!ihlpf!nevin1 (312) 510-6194 ' ) ) "The secret compartment of my ring I fill / / _ , __o ____ with an Underdog super-energy pill." / (_