digitalmars.D.learn - Why can I convert a d_time to int without error?
- Grzegorz Adam Hankiewicz (25/25) Dec 31 2005 Hi, I'm testing this code:
- Manfred Nowak (18/21) Dec 31 2005 [...]
- Grzegorz Adam Hankiewicz (5/7) Jan 01 2006 Embarressed? No, if I was embarrassed by every mistake I do I would
- S. Chancellor (5/26) Jan 03 2006 No need to be so aggravated. It's an easy mistake to make, and after
- Manfred Nowak (3/5) Jan 03 2006 Same to you. Ever heard of the drama triangle?
- S. Chancellor (5/10) Jan 03 2006 Ever heard "If you can't say something nice, don't say anything at all?"
- Manfred Nowak (10/13) Jan 03 2006 Okay. I see, that the climate of the D-NG has changed drastically.
- John Reimer (17/35) Jan 04 2006 Manfred, you can't use the English-is-a-second-language excuse anymore.
- Ben Phillips (6/31) Jan 02 2006 d_time is an alias rather than a typedef meaning that it is not actually...
- a.c.edwards (21/57) Jan 02 2006 It does not matter whether d_time is a typedef or an alias. The fact rem...
- Manfred Nowak (8/10) Jan 02 2006 [...]
- Chris Sauls (16/33) Jan 02 2006 Quoted directly from http://digitalmars.com/d/type.html
- Manfred Nowak (40/46) Jan 03 2006 [...]
- a.c.edwards (9/19) Jan 02 2006 Maybe you and I are reading two completely different specs. The one I re...
- Derek Parnell (8/17) Jan 03 2006 I suggest that the 'mistake' in that part of the documentation (Usual
- Manfred Nowak (6/7) Jan 03 2006 Changing the wording would not help much. Please see my answer to
- S. Chancellor (11/17) Jan 03 2006 You are the one who is sorely mistaken. and you don't need to be so
- Manfred Nowak (8/11) Jan 03 2006 Me parece chino.
- jicman (7/13) Jan 04 2006 Manfred,
- Carlos Santander (9/34) Jan 04 2006 Yo pensaba que se refería a lo que S. Chancellor escribió, no a él mismo...
- jicman (7/41) Jan 04 2006 Carlos, ahora que vuelvo a leerlo, entiendo lo que dices. Pense que el ...
Hi, I'm testing this code: [0:gradha noir:0] [~/test]$ cat hello.d import std.stdio; import std.date; int main() { int bad_date = getUTCtime(); d_time good_date = getUTCtime(); writefln("This is bad: %s", toDateString(bad_date)); writefln("This is good: %s", toDateString(good_date)); return 0; } [0:gradha noir:0] [~/test]$ ./hello This is bad: Sun Dec 07 1969 This is good: Sat Dec 31 2005 Obviously d_time types should not be converted to ints. From str.date documentation I didn't see any warnings about this. In fact, I thought a d_time type would be just like C's simple time data type (t_time) and there would be no problems doing this. The example shows otherwise. Shouldn't the compiler give an error about the conversion? I didn't find any warning switches on dmd's command line help to turn on verbosity about such obvious conversion mistakes. Is this maybe a bug in dmd allowing to convert silently a d_time value to int? I'm using dmd 0.141.
Dec 31 2005
Grzegorz Adam Hankiewicz wrote: [...]I didn't find any warning switches on dmd's command line help to turn on verbosity about such obvious conversion mistakes.[...] Maybe you were too embarressed to see the "-w" warning switch on the command line help. Maybe you have not read http://www.digitalmars.com/d/warnings.html. But if you have a C background as your comparison with t_time suggests you should know the implicit conversion rules obeyed by C and that therefore assigning to a variable may cause loss of data, if the type of the variable is not known exactly to you. It depends on your habits of handlinmg risks what to do in case of unsureness. You decided to take a risk, lost and now critisizes D. You could have stated your prerequisite by inserting code like assert( typeof(getUTCtime()).sizeof<= int.sizeof); and would have been on the warned side forever. -manfred
Dec 31 2005
El Sat, 31 Dec 2005 19:34:53 +0000, Manfred Nowak escribió:Maybe you were too embarressed to see the "-w" warning switch on the command line help.Embarressed? No, if I was embarrassed by every mistake I do I would never ever get out of my mother's basement (oh, wait). I apologise for not having read correctly the output of dmd on the command line and causing so much trouble.
Jan 01 2006
No need to be so aggravated. It's an easy mistake to make, and after all, this is the D.learn newsgroup. Manfred Nowak <svv1999 hotmail.com> wrote:Grzegorz Adam Hankiewicz wrote: [...]-- Email works.I didn't find any warning switches on dmd's command line help to turn on verbosity about such obvious conversion mistakes.[...] Maybe you were too embarressed to see the "-w" warning switch on the command line help. Maybe you have not read http://www.digitalmars.com/d/warnings.html. But if you have a C background as your comparison with t_time suggests you should know the implicit conversion rules obeyed by C and that therefore assigning to a variable may cause loss of data, if the type of the variable is not known exactly to you. It depends on your habits of handlinmg risks what to do in case of unsureness. You decided to take a risk, lost and now critisizes D. You could have stated your prerequisite by inserting code like assert( typeof(getUTCtime()).sizeof<= int.sizeof); and would have been on the warned side forever. -manfred
Jan 03 2006
S. Chancellor wrote:No need to be so aggravated. It's an easy mistake to make, and after all, this is the D.learn newsgroup.Same to you. Ever heard of the drama triangle? -manfred
Jan 03 2006
Manfred Nowak <svv1999 hotmail.com> wrote:S. Chancellor wrote:Ever heard "If you can't say something nice, don't say anything at all?" If you don't like stupid questions, don't answer them. -- Email works.No need to be so aggravated. It's an easy mistake to make, and after all, this is the D.learn newsgroup.Same to you. Ever heard of the drama triangle? -manfred
Jan 03 2006
S. Chancellor wrote: [...]Ever heard "If you can't say something nice, don't say anything at all?" If you don't like stupid questions, don't answer them.Okay. I see, that the climate of the D-NG has changed drastically. Instead of polishing up my posts you want me to say nothing. Thats the second time that someone reacts this way to my incapabilities stemming from the fact not to be a native english speaker. I leave the D-community now. Please inform Walter to nominate some other co-editor. -manfred
Jan 03 2006
Manfred Nowak wrote:S. Chancellor wrote: [...]Manfred, you can't use the English-is-a-second-language excuse anymore. Your posts are quite purposeful in your disdain for people or their posts. You seem to have enough of a handle of English to fully understand the points you are getting across. In fact, maybe you are just being a little too cocky with your handle of English. It's like taking a big knife in your hand and deftly twirling it on your fingertips... only to discover that you lack the coordination for the maneuver; in short, it's dangerous, and the way you've been "twirling" your English around is bound to hurt you and others. You could easily avoid this by writing plain and straight English and avoid all attempts at English idiom, sarcasm, or wit. You just can't do it. I've been completely perplexed at some of your posts. You have been your own worst enemy. Maybe I shouldn't have addressed you directly like this. I'm sorry if this offends you, but I believe it needed to be said. -JJREver heard "If you can't say something nice, don't say anything at all?" If you don't like stupid questions, don't answer them.Okay. I see, that the climate of the D-NG has changed drastically. Instead of polishing up my posts you want me to say nothing. Thats the second time that someone reacts this way to my incapabilities stemming from the fact not to be a native english speaker. I leave the D-community now. Please inform Walter to nominate some other co-editor. -manfred
Jan 04 2006
In article <pan.2005.12.31.11.29.06.445640 ya.com>, Grzegorz Adam Hankiewicz says...Hi, I'm testing this code: [0:gradha noir:0] [~/test]$ cat hello.d import std.stdio; import std.date; int main() { int bad_date = getUTCtime(); d_time good_date = getUTCtime(); writefln("This is bad: %s", toDateString(bad_date)); writefln("This is good: %s", toDateString(good_date)); return 0; } [0:gradha noir:0] [~/test]$ ./hello This is bad: Sun Dec 07 1969 This is good: Sat Dec 31 2005 Obviously d_time types should not be converted to ints. From str.date documentation I didn't see any warnings about this. In fact, I thought a d_time type would be just like C's simple time data type (t_time) and there would be no problems doing this. The example shows otherwise. Shouldn't the compiler give an error about the conversion? I didn't find any warning switches on dmd's command line help to turn on verbosity about such obvious conversion mistakes. Is this maybe a bug in dmd allowing to convert silently a d_time value to int? I'm using dmd 0.141.d_time is an alias rather than a typedef meaning that it is not actually a new type Currently in data.d, d_time is declared as "alias long d_time;" Perhaps this should be changed "typedef long d_time;"? I think it should
Jan 02 2006
In article <dpbd1t$31bq$1 digitaldaemon.com>, Ben Phillips says...In article <pan.2005.12.31.11.29.06.445640 ya.com>, Grzegorz Adam Hankiewicz says...It does not matter whether d_time is a typedef or an alias. The fact remains that if you assign a long (i.e., d_time) to an int, implicit conversion will occur. output: C:\d>dtime -1486618624 The documentation clearly states that a typedef will be implicitly converted to it's base type during assignment. See: http://www.digitalmars.com/d/type.html Rule number 1 under "Usual Arithmetic Conversions" Regards, AndrewHi, I'm testing this code: [0:gradha noir:0] [~/test]$ cat hello.d import std.stdio; import std.date; int main() { int bad_date = getUTCtime(); d_time good_date = getUTCtime(); writefln("This is bad: %s", toDateString(bad_date)); writefln("This is good: %s", toDateString(good_date)); return 0; } [0:gradha noir:0] [~/test]$ ./hello This is bad: Sun Dec 07 1969 This is good: Sat Dec 31 2005 Obviously d_time types should not be converted to ints. From str.date documentation I didn't see any warnings about this. In fact, I thought a d_time type would be just like C's simple time data type (t_time) and there would be no problems doing this. The example shows otherwise. Shouldn't the compiler give an error about the conversion? I didn't find any warning switches on dmd's command line help to turn on verbosity about such obvious conversion mistakes. Is this maybe a bug in dmd allowing to convert silently a d_time value to int? I'm using dmd 0.141.d_time is an alias rather than a typedef meaning that it is not actually a new type Currently in data.d, d_time is declared as "alias long d_time;" Perhaps this should be changed "typedef long d_time;"? I think it should
Jan 02 2006
a.c.edwards wrote: [...]The documentation clearly states that a typedef will be implicitly converted to it's base type during assignment.[...] Sorry, there is no such clear statement in the docs. Assignment is not an _arithmetic_ operator. According to the specs the result of an assignment of a typedef'd type to any other type than its base type is not defined. -manfred
Jan 02 2006
Manfred Nowak wrote:a.c.edwards wrote: [...]Quoted directly from http://digitalmars.com/d/type.html D has a lot of types, both built in and derived. It would be tedious to require casts for every type conversion, so implicit conversions step in to handle the obvious ones automatically. A typedef can be implicitly converted to its underlying type, but going the other way requires an explicit conversion. For example: -- Chris SaulsThe documentation clearly states that a typedef will be implicitly converted to it's base type during assignment.[...] Sorry, there is no such clear statement in the docs. Assignment is not an _arithmetic_ operator. According to the specs the result of an assignment of a typedef'd type to any other type than its base type is not defined. -manfred
Jan 02 2006
Chris Sauls cited: [...][...] Thank you for that clarification. 1) The first assignment shows the case where a variable of a typedef'd type is assigned to a variable of the base type of the typedef ... ... while I was reasoning over assignments to "any other type than its base type". 2) The second assignment shows the case where a variable of the base type is assigned to a variable of a typedef'd type ... ... and according to the comment it is erroneous. This can happen only if the LHS of the assignment is _not_ converted to its base type. This again can only happen if the rules for "Usual Arithmetic Conversions" do _not_ apply. 3) The third assignment shows the case 2) again but with the addition of a `cast' to the typedef'd type with the comment, that this OK. The `cast' would be superfluous if the rules for "Usual Arithmetic Conversions" would apply ... as shown in case 2). From facts 2) and 3) follows already that the rules stated under "Usual Arithmetic Conversions" do _not_ apply to assignments. Further thinking that the examples above are special cases would lead to code: typedef int myint; myint a,b,c; a= b + c; // error, because `b + c' is converted to `int' Therefore the rules stated under "Usual Arithmetic Conversions" are incomplete. At least rule 1) must be reformulated. For example: 1. If at least one operand is typedef'd then 1. if it is the same typedef, no more conversions are done 2. any typedef on the left of an assignment remains unconverted 3. all remaining typedef's are converted to their underlying type. Note, that 1.2) may be placed wrongly in this section of the docs because in general the assignment is not an numeric or arithmetic operator. -manfred ( x-post and f'up to D.bugs)
Jan 03 2006
In article <Xns973FEC134871Asvv1999hotmailcom 63.105.9.61>, Manfred Nowak says...a.c.edwards wrote: [...]Maybe you and I are reading two completely different specs. The one I read (i.e. the link I provided) was extremely clear to me. Or maybe it's just that my inexperience as a programmer does not grant me the necessary required knowlege to discern what is clear from what is not. But I would go as far as to suggest that if is clear to neophyte, then it is pretty damn clear to just about anyone else except those who chose not to read it. AndrewThe documentation clearly states that a typedef will be implicitly converted to it's base type during assignment.[...] Sorry, there is no such clear statement in the docs. Assignment is not an _arithmetic_ operator. According to the specs the result of an assignment of a typedef'd type to any other type than its base type is not defined. -manfred
Jan 02 2006
On Tue, 03 Jan 2006 09:12:27 +1100, Manfred Nowak <svv1999 hotmail.com> wrote:a.c.edwards wrote: [...]I suggest that the 'mistake' in that part of the documentation (Usual Arithmetic Conversions) is that it uses the word "arithmetic" when it really just means "numeric". -- Derek Parnell Melbourne, AustraliaThe documentation clearly states that a typedef will be implicitly converted to it's base type during assignment.[...] Sorry, there is no such clear statement in the docs. Assignment is not an _arithmetic_ operator. According to the specs the result of an assignment of a typedef'd type to any other type than its base type is not defined.
Jan 03 2006
Derek Parnell wrote: [...]uses the word "arithmetic" when it really just means "numeric".Changing the wording would not help much. Please see my answer to "Chris Sauls" posting. -manfred
Jan 03 2006
Manfred Nowak <svv1999 hotmail.com> wrote:Derek Parnell wrote: [...]You are the one who is sorely mistaken. and you don't need to be so angsty. If d_time is a typedef of long, and long can be converted to an int. Then there's no reason a d_time can't be converted to a long and then to an int. The point of a typedef is keeping other stuff out of your typedefs, not keeping your typedefs out of other stuff. ÀComprende? -- Email works.uses the word "arithmetic" when it really just means "numeric".Changing the wording would not help much. Please see my answer to "Chris Sauls" posting. -manfred
Jan 03 2006
S. Chancellor wrote: [...]The point of a typedef is keeping other stuff out of your typedefs, not keeping your typedefs out of other stuff. ÀComprende?Me parece chino. The rules do not demand to convert my typedefs into other stuff on arithmetics? -manfred P.S.: If you want to take over censorship for my postings I will be glad to have them polished by you.
Jan 03 2006
Manfred Nowak says...S. Chancellor wrote: [...]Manfred, you made a mistake on the Spanish statement above. It should had been, "me pareces chino." Just clearing things up. :-) josé PS: Sorry, I had to do it. :-)The point of a typedef is keeping other stuff out of your typedefs, not keeping your typedefs out of other stuff. ÀComprende?Me parece chino.
Jan 04 2006
jicman escribió:Manfred Nowak says...Yo pensaba que se refería a lo que S. Chancellor escribió, no a él mismo. A mí me pareció correcto. For those lost in translation: Manfred wrote "it seems chinese to me". José argues that it should've been "you seem chinese to me", which I think is not what Manfred tried to say.S. Chancellor wrote: [...]Manfred, you made a mistake on the Spanish statement above. It should had been, "me pareces chino."The point of a typedef is keeping other stuff out of your typedefs, not keeping your typedefs out of other stuff. ÀComprende?Me parece chino.Just clearing things up. :-) josé PS: Sorry, I had to do it. :-)Same here :P -- Carlos Santander Bernal
Jan 04 2006
Carlos Santander says...jicman escribió:Carlos, ahora que vuelvo a leerlo, entiendo lo que dices. Pense que el estaba llamando chino al otro. Ok, buena aclaracion. :-) Folks, Carlos just straightened me out. I misinterpreted the statement because of the heated battle and so I thought something that it was not. Carlos, in his good nature, cleared the statement for me. :-) Carry on... :-)Manfred Nowak says...Yo pensaba que se refería a lo que S. Chancellor escribió, no a él mismo. A mí me pareció correcto.S. Chancellor wrote: [...]Manfred, you made a mistake on the Spanish statement above. It should had been, "me pareces chino."The point of a typedef is keeping other stuff out of your typedefs, not keeping your typedefs out of other stuff. ÀComprende?Me parece chino.For those lost in translation: Manfred wrote "it seems chinese to me". José argues that it should've been "you seem chinese to me", which I think is not what Manfred tried to say.Just clearing things up. :-) josé PS: Sorry, I had to do it. :-)Same here :P -- Carlos Santander Bernal
Jan 04 2006