digitalmars.D - What are 'op' codes?
- kinghajj (2/2) Aug 18 2004 My guess is that they handle what the class does when used in an operate...
- J C Calvarese (13/15) Aug 18 2004 Thanks to the power of Google, I'll submit my guess.
- John Reimer (3/25) Aug 19 2004 Wasn't he just asking about operator overloading? You know... opCmp
- kinghajj (4/29) Aug 19 2004 Yes, I was, and I've already answered my own question (by reading the
- kinghajj (5/37) Aug 19 2004 OK, now another question about the 'op' codes.
- John Reimer (10/18) Aug 19 2004 Operator overloading...
- Stephen Waits (7/11) Aug 19 2004 Hopefully you can't.
- kinghajj (2/13) Aug 19 2004 I never said it was a good idea, I was just wondering if it could be don...
-
Matthew
(2/12)
Aug 19 2004
Hear, hear! (And I'm supposed to be a C++ honcho!
) - Andy Friesen (26/32) Aug 19 2004 It's not the "D way", but it's still pretty simple:
- kinghajj (4/36) Aug 19 2004 It's best to provide multiple options, to have more than one way, no? If...
- Andy Friesen (6/18) Aug 19 2004 I think I prefer the C++ way because it offers compile time typesafety,
- Ivan Senji (31/49) Aug 19 2004 someone
-
Regan Heath
(29/56)
Aug 19 2004
On Thu, 19 Aug 2004 23:39:56 +0200, Ivan Senji
- Matthew (3/48) Aug 19 2004 I'm skeptical that you'll get many true C++ aficionados who also grok ot...
- J C Calvarese (5/30) Aug 19 2004 Apparently so. If he would've asked what op functions like opCmp were I ...
- John Reimer (4/11) Aug 19 2004 Hey, what are you saying, Justin? You looking for a fight with me and
- J C Calvarese (6/17) Aug 19 2004 LOL, no.
My guess is that they handle what the class does when used in an operater (like '==', '+', etc.). Is that so, and how do you use them?
Aug 18 2004
kinghajj wrote:My guess is that they handle what the class does when used in an operater (like '==', '+', etc.). Is that so, and how do you use them?Thanks to the power of Google, I'll submit my guess. http://www.wlug.org.nz/OpCodes Op Codes The names given to individual instructions in AssemblyLanguage. Different CPU families have different op codes, and assembler has mnemonic names for the different instructions (which to the CPU are just 1s and 0s). For Intel x86 machines, common codes include JMP, AND, XOR, INT, MOVL, PUSH, POP, CALL, and so on. -- Justin (a/k/a jcc7) http://jcc_7.tripod.com/d/
Aug 18 2004
J C Calvarese wrote:kinghajj wrote:Wasn't he just asking about operator overloading? You know... opCmp opEquals, opAdd, and such...My guess is that they handle what the class does when used in an operater (like '==', '+', etc.). Is that so, and how do you use them?Thanks to the power of Google, I'll submit my guess. http://www.wlug.org.nz/OpCodes Op Codes The names given to individual instructions in AssemblyLanguage. Different CPU families have different op codes, and assembler has mnemonic names for the different instructions (which to the CPU are just 1s and 0s). For Intel x86 machines, common codes include JMP, AND, XOR, INT, MOVL, PUSH, POP, CALL, and so on.
Aug 19 2004
In article <cg1mdh$12mg$1 digitaldaemon.com>, John Reimer says...J C Calvarese wrote:Yes, I was, and I've already answered my own question (by reading the documentation "Operator Overloading"). It's a nice feature : I can see how it's so usefull!kinghajj wrote:Wasn't he just asking about operator overloading? You know... opCmp opEquals, opAdd, and such...My guess is that they handle what the class does when used in an operater (like '==', '+', etc.). Is that so, and how do you use them?Thanks to the power of Google, I'll submit my guess. http://www.wlug.org.nz/OpCodes Op Codes The names given to individual instructions in AssemblyLanguage. Different CPU families have different op codes, and assembler has mnemonic names for the different instructions (which to the CPU are just 1s and 0s). For Intel x86 machines, common codes include JMP, AND, XOR, INT, MOVL, PUSH, POP, CALL, and so on.
Aug 19 2004
In article <cg1oah$18br$1 digitaldaemon.com>, kinghajj says...In article <cg1mdh$12mg$1 digitaldaemon.com>, John Reimer says...OK, now another question about the 'op' codes. You know how C++ has the cout stream, and it workd like this: cout << "Whatever, " << variable << " again"; How could you do that in D?J C Calvarese wrote:Yes, I was, and I've already answered my own question (by reading the documentation "Operator Overloading"). It's a nice feature : I can see how it's so usefull!kinghajj wrote:Wasn't he just asking about operator overloading? You know... opCmp opEquals, opAdd, and such...My guess is that they handle what the class does when used in an operater (like '==', '+', etc.). Is that so, and how do you use them?Thanks to the power of Google, I'll submit my guess. http://www.wlug.org.nz/OpCodes Op Codes The names given to individual instructions in AssemblyLanguage. Different CPU families have different op codes, and assembler has mnemonic names for the different instructions (which to the CPU are just 1s and 0s). For Intel x86 machines, common codes include JMP, AND, XOR, INT, MOVL, PUSH, POP, CALL, and so on.
Aug 19 2004
OK, now another question about the 'op' codes. You know how C++ has the cout stream, and it workd like this: cout << "Whatever, " << variable << " again"; How could you do that in D?Operator overloading... You can do the exact same thing in D if the library you are using has overloaded those operators in such a fashion. Although overloading shift operators in such a way is not popular to everyone in D (I don't like it). The only library that currently lets you do it that way, that I know of, is mango on its io streams. But mango also gives an alternative way to do the same thing, thankfully. Later, John
Aug 19 2004
kinghajj wrote:You know how C++ has the cout stream, and it workd like this: cout << "Whatever, " << variable << " again"; How could you do that in D?Hopefully you can't. The thing is, you aren't going to find many, or any, in this group of people that believe that overloading operator << to deal with stream output is a good idea. Personally, I suggest you forget you ever saw that in C++. --Steve
Aug 19 2004
In article <cg2q79$284j$1 digitaldaemon.com>, Stephen Waits says...kinghajj wrote:I never said it was a good idea, I was just wondering if it could be done.You know how C++ has the cout stream, and it workd like this: cout << "Whatever, " << variable << " again"; How could you do that in D?Hopefully you can't. The thing is, you aren't going to find many, or any, in this group of people that believe that overloading operator << to deal with stream output is a good idea. Personally, I suggest you forget you ever saw that in C++. --Steve
Aug 19 2004
"Stephen Waits" <steve waits.net> wrote in message news:cg2q79$284j$1 digitaldaemon.com...kinghajj wrote:Hear, hear! (And I'm supposed to be a C++ honcho! <g>)You know how C++ has the cout stream, and it workd like this: cout << "Whatever, " << variable << " again"; How could you do that in D?Hopefully you can't. The thing is, you aren't going to find many, or any, in this group of people that believe that overloading operator << to deal with stream output is a good idea. Personally, I suggest you forget you ever saw that in C++.
Aug 19 2004
kinghajj wrote:OK, now another question about the 'op' codes. You know how C++ has the cout stream, and it workd like this: cout << "Whatever, " << variable << " again"; How could you do that in D?It's not the "D way", but it's still pretty simple: class CppStream { CppStream opShl(int x) { write(x); return this; } CppStream opShl(float f) { write(f); return this; } } Other classes can define << behaviour between themselves and streams by implementing an opShl_r() method: class Thing { CppStream opShl_r(CppStream lhs) { // In this case, 'this' is the left-hand-side argument // not the right hand side. lhs.write(this); return lhs; } } Like I said, though, it's supposedly not the "D way", so you will be set on fire and chased out of town or something (in that exact order) if you do it. -- andy
Aug 19 2004
In article <cg2see$29mf$1 digitaldaemon.com>, Andy Friesen says...kinghajj wrote:It's best to provide multiple options, to have more than one way, no? If someone could implement the C++ iostreams, maybe more C++ programmers would look into it. But, of course, still have writef() for us :)OK, now another question about the 'op' codes. You know how C++ has the cout stream, and it workd like this: cout << "Whatever, " << variable << " again"; How could you do that in D?It's not the "D way", but it's still pretty simple: class CppStream { CppStream opShl(int x) { write(x); return this; } CppStream opShl(float f) { write(f); return this; } } Other classes can define << behaviour between themselves and streams by implementing an opShl_r() method: class Thing { CppStream opShl_r(CppStream lhs) { // In this case, 'this' is the left-hand-side argument // not the right hand side. lhs.write(this); return lhs; } } Like I said, though, it's supposedly not the "D way", so you will be set on fire and chased out of town or something (in that exact order) if you do it. -- andy
Aug 19 2004
kinghajj wrote:In article <cg2see$29mf$1 digitaldaemon.com>, Andy Friesen says...I think I prefer the C++ way because it offers compile time typesafety, as opposed to runtime. (it's also hypothetically a hair faster because of this) That being said, it's best not to think in C++ when writing D. -- andyLike I said, though, it's supposedly not the "D way", so you will be set on fire and chased out of town or something (in that exact order) if you do it. -- andyIt's best to provide multiple options, to have more than one way, no? If someone could implement the C++ iostreams, maybe more C++ programmers would look into it. But, of course, still have writef() for us :)
Aug 19 2004
"Andy Friesen" <andy ikagames.com> wrote in message news:cg2tlb$2an8$1 digitaldaemon.com...kinghajj wrote:someoneIn article <cg2see$29mf$1 digitaldaemon.com>, Andy Friesen says...Like I said, though, it's supposedly not the "D way", so you will be set on fire and chased out of town or something (in that exact order) if you do it. -- andyIt's best to provide multiple options, to have more than one way, no? Ifintocould implement the C++ iostreams, maybe more C++ programmers would lookI prefer the C++ way too! Plus: writef is a really nice function but it caused problems to me i wouldn't get if i used something like iostream << I was printing strings: with this code: char[] str;//some string writef(str); It all looks very simple and nice but what if the string i want to print is "%"? You get a nice little exception: "Error: std.format invalid specifier" So basically i can't use writef to print strings for wich i don't know what they contain? The best way IMO would be to have something like iostreams combined with formating when needed. like this: int x; char[] str = "%"; cout << str << format("%5d",x); This would print "str" correctly.it. But, of course, still have writef() for us :)I think I prefer the C++ way because it offers compile time typesafety, as opposed to runtime. (it's also hypothetically a hair faster because of this)That being said, it's best not to think in C++ when writing D.<< and >> as stream operators appeared in C++ but they shouldn't automatically be non-D way of thinking. As you said: they are a nice typesafe compiletime way of doing streams. What is there not to like about that? And: It is not operator abuse if you use an operator in a way that everyone can understand and use. example: opShl defined on stream: Who would ever think that "stream << 5 << "Hello""; means that you are shifting a stream? :)-- andy
Aug 19 2004
On Thu, 19 Aug 2004 23:39:56 +0200, Ivan Senji <ivan.senji public.srce.hr> wrote: <snip>I prefer the C++ way too! Plus: writef is a really nice function but it caused problems to me i wouldn't get if i used something like iostream << I was printing strings: with this code: char[] str;//some string writef(str); It all looks very simple and nice but what if the string i want to print is "%"? You get a nice little exception: "Error: std.format invalid specifier" So basically i can't use writef to print strings for wich i don't know what they contain?Can't you do the same as I do with printf in C? i.e. The solution is: printf("%s",str); //or is it %S? in other words, always specify a format string, that way the string you're printing does not get interpreted as a format string. However... Looking at the function signature in the phobos docs writef is defined as: void writef(...); Combined with the description "Arguments are formatted per the format strings and written to stdout" suggests to me that all arguments are treated as format strings, meaning you cannot do what I have shown above with writef. This seems wrong to me. In your case you simply want a 'write' function that does not expect a format string.The best way IMO would be to have something like iostreams combined with formating when needed. like this: int x; char[] str = "%"; cout << str << format("%5d",x); This would print "str" correctly.Whats the big advantage of 'compiletime' type safety over 'runtime'? What bug does << prevent that you get with writef (which is type safe)?That being said, it's best not to think in C++ when writing D.<< and >> as stream operators appeared in C++ but they shouldn't automatically be non-D way of thinking. As you said: they are a nice typesafe compiletime way of doing streams. What is there not to like about that?And: It is not operator abuse if you use an operator in a way that everyone can understand and use.The word 'everyone' is incorrect. A lot of people might know what it means, but only if they come from a c++ background. Personally I came from C, and had no idea what it did the first time I saw it, I assumed it was shifting something but could not decide what.example: opShl defined on stream: Who would ever think that "stream << 5 << "Hello""; means that you are shifting a stream?Yes, that is exactly what I thought (when I first saw it), and it made no sense whatsoever. Regan -- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
Aug 19 2004
"kinghajj" <kinghajj_member pathlink.com> wrote in message news:cg2t3j$2a13$1 digitaldaemon.com...In article <cg2see$29mf$1 digitaldaemon.com>, Andy Friesen says...I'm skeptical that you'll get many true C++ aficionados who also grok other languages that would advocate it's being included a priori in D.kinghajj wrote:It's best to provide multiple options, to have more than one way, no? If someone could implement the C++ iostreams, maybe more C++ programmers would look into it. But, of course, still have writef() for us :)OK, now another question about the 'op' codes. You know how C++ has the cout stream, and it workd like this: cout << "Whatever, " << variable << " again"; How could you do that in D?It's not the "D way", but it's still pretty simple: class CppStream { CppStream opShl(int x) { write(x); return this; } CppStream opShl(float f) { write(f); return this; } } Other classes can define << behaviour between themselves and streams by implementing an opShl_r() method: class Thing { CppStream opShl_r(CppStream lhs) { // In this case, 'this' is the left-hand-side argument // not the right hand side. lhs.write(this); return lhs; } } Like I said, though, it's supposedly not the "D way", so you will be set on fire and chased out of town or something (in that exact order) if you do it. -- andy
Aug 19 2004
In article <cg1mdh$12mg$1 digitaldaemon.com>, John Reimer says...J C Calvarese wrote:Apparently so. If he would've asked what op functions like opCmp were I would've answered a whole other question. In the future, I guess I'll leave the psychic hotline questions to Miss Cleo.... jcc7kinghajj wrote:Wasn't he just asking about operator overloading? You know... opCmp opEquals, opAdd, and such...My guess is that they handle what the class does when used in an operater (like '==', '+', etc.). Is that so, and how do you use them?Thanks to the power of Google, I'll submit my guess. http://www.wlug.org.nz/OpCodes Op Codes The names given to individual instructions in AssemblyLanguage. Different CPU families have different op codes, and assembler has mnemonic names for the different instructions (which to the CPU are just 1s and 0s). For Intel x86 machines, common codes include JMP, AND, XOR, INT, MOVL, PUSH, POP, CALL, and so on.
Aug 19 2004
J C Calvarese wrote:Apparently so. If he would've asked what op functions like opCmp were I would've answered a whole other question. In the future, I guess I'll leave the psychic hotline questions to Miss Cleo.... jcc7Hey, what are you saying, Justin? You looking for a fight with me and my psychic abilities? j/k :-)
Aug 19 2004
In article <cg294n$1v55$2 digitaldaemon.com>, John Reimer says...J C Calvarese wrote:LOL, no. I'm just tired of when people ask a vague question, and I get criticized for answering the wrong question. Just too thin skinned, I suppose. I wasn't mad at you.Apparently so. If he would've asked what op functions like opCmp were I would've answered a whole other question. In the future, I guess I'll leave the psychic hotline questions to Miss Cleo.... jcc7Hey, what are you saying, Justin? You looking for a fight with me and my psychic abilities?j/k :-)jcc7
Aug 19 2004