digitalmars.D - typeof headache
- Dan Williams (22/22) Jun 30 2004 I'm having a little trouble with typeof().
- Dan Williams (16/38) Jun 30 2004 Thinking about it I expect someone will say at some point something like...
- me (15/18) Jun 30 2004 I suggest that D could addopt the less ambiguous (and less prone to erro...
- Dan Williams (22/40) Jun 30 2004 Hmmmm, an 'is' operator. Yes, that might work... but would it allow
- Dan Williams (6/24) Jun 30 2004 I just noticed there already is an 'is' operator, so it would seem that ...
- Mike Swieton (8/10) Jun 30 2004 That is already implemented by casts. The cast operator returns null if ...
- Norbert Nemec (8/39) Jun 30 2004 Did you try typeid?
- Bent Rasmussen (7/12) Jun 30 2004 I did
- Dan Williams (10/23) Jun 30 2004 Hmmmm, you know when using cast() you do something like:
- Bent Rasmussen (5/7) Jun 30 2004 If I understand this correctly typeof maps from values to types and int ...
- Dan Williams (3/11) Jun 30 2004 You are correct.
- Dan Williams (18/57) Jun 30 2004 Gah... typeid? I'll have to go and look that up and play with it. I
- Dan Williams (45/84) Jun 30 2004 Ok I've been and tested this typeid thing. I know C has typeid, but beca...
- Walter (24/116) Jun 30 2004 typeid returns an instance of class TypeInfo corresponding to the type o...
- Dan Williams (15/153) Jun 30 2004 Ahhhh, excellent, that makes sense :)
- Hauke Duden (8/13) Jun 30 2004 Hmmm. This got me thinking: how would one check if one TypeInfo instance...
- Walter (5/12) Jun 30 2004 All class objects are instances of TypeClass, which is derived from
- Andy Friesen (8/23) Jun 30 2004 Speaking of which, how much arm-twisting would it take to get more
- Walter (3/8) Jun 30 2004 TypeInfo will get better.
- Daniel Horn (7/38) Jun 30 2004 I made a vector class with a static size member
- Regan Heath (16/71) Jun 30 2004 Hmm... but say you now make a static class member called sizeof..
I'm having a little trouble with typeof(). The D documentation says: "Typeof is a way to specify a type based on the type of an expression." That's fair enough, but in that case how do you DETECT the current type of an expression? I was hoping that either typeof would return something to tell me a current type, or that I could at the very least to typeof comparison checking such as if (typeof('c') == typeof(int)) - something like that in any case. However, the compiler keeps yelling that it expects a dot, and I'm really not sure how to do what I want. Things like typeof(a).sizeof work fine (by the way, why was size deprecated in favour of sizeof? To my mind, size is more fitting for a property, i.e. a.size, and sizeof for a function, i.e. sizeof(a). But never mind...) however the code examples on the D site are very sparse when it comes to typeof(), and some do not actually work at all. I guess I'm a little confused about the purpose of typeof(), as my initial logical assumption would be that it would check what type something is, and yet the documentation (keyword: "specify") makes me think that it's actually more like cast(). Which brings me to two questions: if typeof() is actually like cast(), why is it there? And how can I detect the type of a variable (or expression)? Sorry if this is a stupid question, but a search of the D newsgroups and a Google of the site did not reveal anything to help me.
Jun 30 2004
Thinking about it I expect someone will say at some point something like, "D is statically typed, therefore you know the type of all variables already, so why do you need to detect the type?" So I'll quickly point out that in the case of a union or something you may not always know what data type is in use, and typeof would be very useful there. There are other cases too where you may not actually know the data type of a variable. I propose something like a type or typeof property, i.e. a.type or a.typeof, just like there is a.sizeof. Unless there's a better way to do this? "Dan Williams" <dnews ithium.NOSPAM.net> wrote in message news:cbu8rc$2rkn$1 digitaldaemon.com...I'm having a little trouble with typeof(). The D documentation says: "Typeof is a way to specify a type based on the type of an expression." That's fair enough, but in that case how do you DETECT the current type of an expression? I was hoping that either typeof would return something to tell me acurrenttype, or that I could at the very least to typeof comparison checking such as if (typeof('c') == typeof(int)) - something like that in any case. However, the compiler keeps yelling that it expects a dot, and I'm really not sure how to do what I want. Things like typeof(a).sizeof work fine (by the way, why was size deprecated in favour of sizeof? To my mind, size is more fitting for a property, i.e. a.size, and sizeof for a function, i.e. sizeof(a). But never mind...) however the code examples on the D site are very sparse when it comes to typeof(), and some do not actually work atall.I guess I'm a little confused about the purpose of typeof(), as my initial logical assumption would be that it would check what type something is,andyet the documentation (keyword: "specify") makes me think that it'sactuallymore like cast(). Which brings me to two questions: if typeof() is actually like cast(), why is it there? And how can I detect the type of a variable (or expression)? Sorry if this is a stupid question, but a search of the D newsgroups and a Google of the site did not reveal anything to help me.
Jun 30 2004
I was hoping that either typeof would return something to tell me acurrenttype, or that I could at the very least to typeof comparison checking such as if (typeof('c') == typeof(int)) - something like that in any case.I suggest that D could addopt the less ambiguous (and less prone to error) 'is' operator. e.g class Y {} class X : Y {} X x = new X(); Y y = new Y(); if (x is y) ..; //x is either a 'Y' or descends from it - they are under the same branch of the inheritence tree this works equally well for types if (x is X) ...; //as before, is either of that type or a descendent I guess you could d-ify it to : if (x typeof y) ..; but to my eyes that is less readable.
Jun 30 2004
Hmmmm, an 'is' operator. Yes, that might work... but would it allow something like: if (a is int) etc. With typeof(), I would envisage something like; if (typeof(a) == int) if (typeof(a) == some_constant_meaning_int) if (typeof(a) == typeof(int)) ...that kind of thing. But maybe an effective solution is to combine your 'is' operator with my idea for a typeof property: if (a.is(int)) that is admittedly not as readable/semantic as (a is int) however it would not require any extra operators. Of course, the problem is that 'is' then becomes a method and not a property, which is undesirable. Personally I think either (a is int) or a.type are the best options (probably a.typeof rather than a.type seeing as that seems to be the style for D). "me" <memsom interalpha.co.uk> wrote in message news:cbu9ta$2v9p$1 digitaldaemon.com...suchI was hoping that either typeof would return something to tell me acurrenttype, or that I could at the very least to typeof comparison checkingtheas if (typeof('c') == typeof(int)) - something like that in any case.I suggest that D could addopt the less ambiguous (and less prone to error) 'is' operator. e.g class Y {} class X : Y {} X x = new X(); Y y = new Y(); if (x is y) ..; //x is either a 'Y' or descends from it - they are undersame branch of the inheritence tree this works equally well for types if (x is X) ...; //as before, is either of that type or a descendent I guess you could d-ify it to : if (x typeof y) ..; but to my eyes that is less readable.
Jun 30 2004
I just noticed there already is an 'is' operator, so it would seem that one is out... "me" <memsom interalpha.co.uk> wrote in message news:cbu9ta$2v9p$1 digitaldaemon.com...suchI was hoping that either typeof would return something to tell me acurrenttype, or that I could at the very least to typeof comparison checkingtheas if (typeof('c') == typeof(int)) - something like that in any case.I suggest that D could addopt the less ambiguous (and less prone to error) 'is' operator. e.g class Y {} class X : Y {} X x = new X(); Y y = new Y(); if (x is y) ..; //x is either a 'Y' or descends from it - they are undersame branch of the inheritence tree this works equally well for types if (x is X) ...; //as before, is either of that type or a descendent I guess you could d-ify it to : if (x typeof y) ..; but to my eyes that is less readable.
Jun 30 2004
On Wed, 30 Jun 2004 12:58:34 +0100, me wrote:if (x is y) ..; //x is either a 'Y' or descends from it - they are under the same branch of the inheritence treeThat is already implemented by casts. The cast operator returns null if the objects are unrelated: if (cast(y) x) ...; Mike Swieton __ It's kind of fun to do the impossible. - Walt Disney
Jun 30 2004
Did you try typeid? ---- if(typeid(typeof(a)) == typeid(typeof(b))) ... ---- I did not try it. I recall Walter mentioning long-term-ideas about handling types directly, but that's certainly post-1.0 Dan Williams wrote:I'm having a little trouble with typeof(). The D documentation says: "Typeof is a way to specify a type based on the type of an expression." That's fair enough, but in that case how do you DETECT the current type of an expression? I was hoping that either typeof would return something to tell me a current type, or that I could at the very least to typeof comparison checking such as if (typeof('c') == typeof(int)) - something like that in any case. However, the compiler keeps yelling that it expects a dot, and I'm really not sure how to do what I want. Things like typeof(a).sizeof work fine (by the way, why was size deprecated in favour of sizeof? To my mind, size is more fitting for a property, i.e. a.size, and sizeof for a function, i.e. sizeof(a). But never mind...) however the code examples on the D site are very sparse when it comes to typeof(), and some do not actually work at all. I guess I'm a little confused about the purpose of typeof(), as my initial logical assumption would be that it would check what type something is, and yet the documentation (keyword: "specify") makes me think that it's actually more like cast(). Which brings me to two questions: if typeof() is actually like cast(), why is it there? And how can I detect the type of a variable (or expression)? Sorry if this is a stupid question, but a search of the D newsgroups and a Google of the site did not reveal anything to help me.
Jun 30 2004
Did you try typeid? ---- if(typeid(typeof(a)) == typeid(typeof(b))) ... ---- I did not try it.I did printf("%i",typeid(typeof(0)) === typeid(typeof(0))); printf("\n%i",typeid(typeof(0)) === typeid(typeof(true))); prints 1 0 Notice the use of the "===" operator.
Jun 30 2004
Hmmmm, you know when using cast() you do something like: bit a; int b; b = cast(int) a; Well, I kinda assumed I could do the same with typeof/typeid/whatever? i.e. printf("%i",typeid(typeof(0)) === typeid(typeof(int))); ...maybe I better go play with it a bit first and see what happens :) "Bent Rasmussen" <exo bent-rasmussen.info> wrote in message news:cbugq2$7sv$1 digitaldaemon.com...Did you try typeid? ---- if(typeid(typeof(a)) == typeid(typeof(b))) ... ---- I did not try it.I did printf("%i",typeid(typeof(0)) === typeid(typeof(0))); printf("\n%i",typeid(typeof(0)) === typeid(typeof(true))); prints 1 0 Notice the use of the "===" operator.
Jun 30 2004
printf("%i",typeid(typeof(0)) === typeid(typeof(int))); ...maybe I better go play with it a bit first and see what happens :)If I understand this correctly typeof maps from values to types and int is not a value, its a type, hence it doesn't make sense to use typeof on it. Thus use printf("%i",typeid(typeof(0)) === typeid(int)); I'm not quite sure what you're asking for.
Jun 30 2004
You are correct. "Bent Rasmussen" <exo bent-rasmussen.info> wrote in message news:cbujou$chr$1 digitaldaemon.com...printf("%i",typeid(typeof(0)) === typeid(typeof(int))); ...maybe I better go play with it a bit first and see what happens :)If I understand this correctly typeof maps from values to types and int is not a value, its a type, hence it doesn't make sense to use typeof on it. Thus use printf("%i",typeid(typeof(0)) === typeid(int)); I'm not quite sure what you're asking for.
Jun 30 2004
Gah... typeid? I'll have to go and look that up and play with it. I certainly didn't know there even *was* a typeid! Anyhow... I think the comments that have been made about typeof remain valid. "Norbert Nemec" <Norbert.Nemec gmx.de> wrote in message news:cbue48$3eu$1 digitaldaemon.com...Did you try typeid? ---- if(typeid(typeof(a)) == typeid(typeof(b))) ... ---- I did not try it. I recall Walter mentioning long-term-ideas about handling types directly, but that's certainly post-1.0 Dan Williams wrote:theI'm having a little trouble with typeof(). The D documentation says: "Typeof is a way to specify a type based onoftype of an expression." That's fair enough, but in that case how do you DETECT the current typeinan expression? I was hoping that either typeof would return something to tell me a current type, or that I could at the very least to typeof comparison checking such as if (typeof('c') == typeof(int)) - something like thatreallyany case. However, the compiler keeps yelling that it expects a dot, and I'm(bynot sure how to do what I want. Things like typeof(a).sizeof work fineisthe way, why was size deprecated in favour of sizeof? To my mind, sizei.e.more fitting for a property, i.e. a.size, and sizeof for a function,aresizeof(a). But never mind...) however the code examples on the D siteinitialvery sparse when it comes to typeof(), and some do not actually work at all. I guess I'm a little confused about the purpose of typeof(), as mywhylogical assumption would be that it would check what type something is, and yet the documentation (keyword: "specify") makes me think that it's actually more like cast(). Which brings me to two questions: if typeof() is actually like cast(),expression)?is it there? And how can I detect the type of a variable (oraSorry if this is a stupid question, but a search of the D newsgroups andGoogle of the site did not reveal anything to help me.
Jun 30 2004
Ok I've been and tested this typeid thing. I know C has typeid, but because D has typeof I wasn't really expecting typeid and forgot about it. Now, in C you can use typeid on an expression, but in D that confusingly does not appear to be the case. typeid(1) fails. typeid(typeof(1)) works. typeid(int) works. so... I can do: if (typeid(typeof(1)) == typeid(typeof(0)))... ...just as was suggested, and so too can I do: if (typeid(typeof(1)) == typeid(int))... But I cannot do: if (typeof(1) == int)... Surely this is more convoluted than it needs to be? As I see it, a lot of this is overkill. If typeof returns something that equates to an actual type, can we not use that ourselves? I mean, typeid(typeof(0))) is the same as typeid(int)), which means that typeof(0) is int, as expected, but it cannot be used like that. Strange. So I tried this: printf("%d\n", typeid(typeof('c'))); // prints 4257264 printf("%d\n", typeid(typeof(1))); // prints 4257408 printf("%d\n", typeid(int)); // prints 4257408 It would appear, therefore, that some constants are being used, but I cannot find reference to them and do not know what they would be called. The flaw in this theory is that: if (typeid(typeof(1)) == 4257408) fails miserably. It would appear that objects are being used somewhere for some reason, so I give up. Does this mean that I *have* to use (typeid(typeof(a)) == typeid(int)), or is there an alternative method? "Norbert Nemec" <Norbert.Nemec gmx.de> wrote in message news:cbue48$3eu$1 digitaldaemon.com...Did you try typeid? ---- if(typeid(typeof(a)) == typeid(typeof(b))) ... ---- I did not try it. I recall Walter mentioning long-term-ideas about handling types directly, but that's certainly post-1.0 Dan Williams wrote:theI'm having a little trouble with typeof(). The D documentation says: "Typeof is a way to specify a type based onoftype of an expression." That's fair enough, but in that case how do you DETECT the current typeinan expression? I was hoping that either typeof would return something to tell me a current type, or that I could at the very least to typeof comparison checking such as if (typeof('c') == typeof(int)) - something like thatreallyany case. However, the compiler keeps yelling that it expects a dot, and I'm(bynot sure how to do what I want. Things like typeof(a).sizeof work fineisthe way, why was size deprecated in favour of sizeof? To my mind, sizei.e.more fitting for a property, i.e. a.size, and sizeof for a function,aresizeof(a). But never mind...) however the code examples on the D siteinitialvery sparse when it comes to typeof(), and some do not actually work at all. I guess I'm a little confused about the purpose of typeof(), as mywhylogical assumption would be that it would check what type something is, and yet the documentation (keyword: "specify") makes me think that it's actually more like cast(). Which brings me to two questions: if typeof() is actually like cast(),expression)?is it there? And how can I detect the type of a variable (oraSorry if this is a stupid question, but a search of the D newsgroups andGoogle of the site did not reveal anything to help me.
Jun 30 2004
typeid returns an instance of class TypeInfo corresponding to the type of typeid's argument. For example: typeid(int) returns an instance of TypeInfo corresponding to int. If two TypeInfo's represent the same type, then their TypeInfo's will compare equal. The reason you must do: typeid(typeof(0)) == typeid(int) instead of: typeof(0) == int is because of parsing ambiguities. Types and expressions follow different grammar rules, and if there wasn't an easy way to distinguish them, it cannot be parsed. For example: foo[] is that a type array of foo's, or is it the array foo? "Dan Williams" <dnews ithium.NOSPAM.net> wrote in message news:cbuk8c$d8o$1 digitaldaemon.com...Ok I've been and tested this typeid thing. I know C has typeid, butbecauseD has typeof I wasn't really expecting typeid and forgot about it. Now, in C you can use typeid on an expression, but in D that confusingly does not appear to be the case. typeid(1) fails. typeid(typeof(1)) works. typeid(int) works. so... I can do: if (typeid(typeof(1)) == typeid(typeof(0)))... ...just as was suggested, and so too can I do: if (typeid(typeof(1)) == typeid(int))... But I cannot do: if (typeof(1) == int)... Surely this is more convoluted than it needs to be? As I see it, a lot of this is overkill. If typeof returns something that equates to an actual type, can we not use that ourselves? I mean, typeid(typeof(0))) is the same as typeid(int)), which means that typeof(0) is int, as expected, but it cannot be used like that. Strange. So I tried this: printf("%d\n", typeid(typeof('c'))); // prints 4257264 printf("%d\n", typeid(typeof(1))); // prints 4257408 printf("%d\n", typeid(int)); // prints 4257408 It would appear, therefore, that some constants are being used, but Icannotfind reference to them and do not know what they would be called. The flaw in this theory is that: if (typeid(typeof(1)) == 4257408) fails miserably. It would appear that objects are being used somewhere for some reason, so I give up. Does this mean that I *have* to use (typeid(typeof(a)) == typeid(int)), or is there an alternative method? "Norbert Nemec" <Norbert.Nemec gmx.de> wrote in message news:cbue48$3eu$1 digitaldaemon.com...directly,Did you try typeid? ---- if(typeid(typeof(a)) == typeid(typeof(b))) ... ---- I did not try it. I recall Walter mentioning long-term-ideas about handling typestypebut that's certainly post-1.0 Dan Williams wrote:theI'm having a little trouble with typeof(). The D documentation says: "Typeof is a way to specify a type based ontype of an expression." That's fair enough, but in that case how do you DETECT the currentofatinan expression? I was hoping that either typeof would return something to tell me a current type, or that I could at the very least to typeof comparison checking such as if (typeof('c') == typeof(int)) - something like thatreallyany case. However, the compiler keeps yelling that it expects a dot, and I'm(bynot sure how to do what I want. Things like typeof(a).sizeof work fineisthe way, why was size deprecated in favour of sizeof? To my mind, sizei.e.more fitting for a property, i.e. a.size, and sizeof for a function,aresizeof(a). But never mind...) however the code examples on the D sitevery sparse when it comes to typeof(), and some do not actually workis,initialall. I guess I'm a little confused about the purpose of typeof(), as mylogical assumption would be that it would check what type somethingit'sand yet the documentation (keyword: "specify") makes me think thatandwhyactually more like cast(). Which brings me to two questions: if typeof() is actually like cast(),expression)?is it there? And how can I detect the type of a variable (orSorry if this is a stupid question, but a search of the D newsgroupsaGoogle of the site did not reveal anything to help me.
Jun 30 2004
Ahhhh, excellent, that makes sense :) Thankyou for clearing that up! "Walter" <newshound digitalmars.com> wrote in message news:cbuqpf$mtp$1 digitaldaemon.com...typeid returns an instance of class TypeInfo corresponding to the type of typeid's argument. For example: typeid(int) returns an instance of TypeInfo corresponding to int. If two TypeInfo's represent the same type, then their TypeInfo's will compare equal. The reason you must do: typeid(typeof(0)) == typeid(int) instead of: typeof(0) == int is because of parsing ambiguities. Types and expressions follow different grammar rules, and if there wasn't an easy way to distinguish them, it cannot be parsed. For example: foo[] is that a type array of foo's, or is it the array foo? "Dan Williams" <dnews ithium.NOSPAM.net> wrote in message news:cbuk8c$d8o$1 digitaldaemon.com...ofOk I've been and tested this typeid thing. I know C has typeid, butbecauseD has typeof I wasn't really expecting typeid and forgot about it. Now, in C you can use typeid on an expression, but in D that confusingly does not appear to be the case. typeid(1) fails. typeid(typeof(1)) works. typeid(int) works. so... I can do: if (typeid(typeof(1)) == typeid(typeof(0)))... ...just as was suggested, and so too can I do: if (typeid(typeof(1)) == typeid(int))... But I cannot do: if (typeof(1) == int)... Surely this is more convoluted than it needs to be? As I see it, a lotusethis is overkill. If typeof returns something that equates to an actual type, can we notlikethat ourselves? I mean, typeid(typeof(0))) is the same as typeid(int)), which means that typeof(0) is int, as expected, but it cannot be usedforthat. Strange. So I tried this: printf("%d\n", typeid(typeof('c'))); // prints 4257264 printf("%d\n", typeid(typeof(1))); // prints 4257408 printf("%d\n", typeid(int)); // prints 4257408 It would appear, therefore, that some constants are being used, but Icannotfind reference to them and do not know what they would be called. The flaw in this theory is that: if (typeid(typeof(1)) == 4257408) fails miserably. It would appear that objects are being used somewhereorsome reason, so I give up. Does this mean that I *have* to use (typeid(typeof(a)) == typeid(int)),onis there an alternative method? "Norbert Nemec" <Norbert.Nemec gmx.de> wrote in message news:cbue48$3eu$1 digitaldaemon.com...directly,Did you try typeid? ---- if(typeid(typeof(a)) == typeid(typeof(b))) ... ---- I did not try it. I recall Walter mentioning long-term-ideas about handling typesbut that's certainly post-1.0 Dan Williams wrote:I'm having a little trouble with typeof(). The D documentation says: "Typeof is a way to specify a type basedthatthetypetype of an expression." That's fair enough, but in that case how do you DETECT the currentofan expression? I was hoping that either typeof would return something to tell me a current type, or that I could at the very least to typeof comparison checking such as if (typeof('c') == typeof(int)) - something likefineinreallyany case. However, the compiler keeps yelling that it expects a dot, and I'mnot sure how to do what I want. Things like typeof(a).sizeof worksize(bythe way, why was size deprecated in favour of sizeof? To my mind,siteisi.e.more fitting for a property, i.e. a.size, and sizeof for a function,sizeof(a). But never mind...) however the code examples on the Dcast(),areatvery sparse when it comes to typeof(), and some do not actually workis,initialall. I guess I'm a little confused about the purpose of typeof(), as mylogical assumption would be that it would check what type somethingit'sand yet the documentation (keyword: "specify") makes me think thatactually more like cast(). Which brings me to two questions: if typeof() is actually likewhyandexpression)?is it there? And how can I detect the type of a variable (orSorry if this is a stupid question, but a search of the D newsgroupsaGoogle of the site did not reveal anything to help me.
Jun 30 2004
Walter wrote:typeid returns an instance of class TypeInfo corresponding to the type of typeid's argument. For example: typeid(int) returns an instance of TypeInfo corresponding to int. If two TypeInfo's represent the same type, then their TypeInfo's will compare equal.Hmmm. This got me thinking: how would one check if one TypeInfo instance represents a base class of another TypeInfo? As far as I can see no helpful information is included in TypeInfo. This could be a huge problem for functions with arbitrary parameter lists, since then all the information you have about the type is the TypeInfo. Hauke
Jun 30 2004
"Hauke Duden" <H.NS.Duden gmx.net> wrote in message news:cbus58$ots$1 digitaldaemon.com...Hmmm. This got me thinking: how would one check if one TypeInfo instance represents a base class of another TypeInfo? As far as I can see no helpful information is included in TypeInfo.All class objects are instances of TypeClass, which is derived from TypeInfo. In TypeClass, there's a member info giving the .classinfo of the class.This could be a huge problem for functions with arbitrary parameter lists, since then all the information you have about the type is the TypeInfo. Hauke
Jun 30 2004
Walter wrote:typeid returns an instance of class TypeInfo corresponding to the type of typeid's argument. For example: typeid(int) returns an instance of TypeInfo corresponding to int. If two TypeInfo's represent the same type, then their TypeInfo's will compare equal. The reason you must do: typeid(typeof(0)) == typeid(int) instead of: typeof(0) == int is because of parsing ambiguities. Types and expressions follow different grammar rules, and if there wasn't an easy way to distinguish them, it cannot be parsed. For example: foo[] is that a type array of foo's, or is it the array foo?Speaking of which, how much arm-twisting would it take to get more TypeInfo? I'd like to be able to look at delegates and function pointers and pry their argument count/types apart. (it would be extremely handy for generating language bindings) TypeInfo for other 'metatypes' like associative arrays would be greatly useful too. (lastly, the holy grail: public methods that a given class exposes) -- andy
Jun 30 2004
"Andy Friesen" <andy ikagames.com> wrote in message news:cbuu7u$rpd$1 digitaldaemon.com...Speaking of which, how much arm-twisting would it take to get more TypeInfo? I'd like to be able to look at delegates and function pointers and pry their argument count/types apart. (it would be extremely handy for generating language bindings) TypeInfo for other 'metatypes' like associative arrays would be greatly useful too.TypeInfo will get better.
Jun 30 2004
I made a vector class with a static size member strange things happened when size was actually a PROPERTY... what should have been a compiler error turned into a runtime error... and other strange havoc resulted when trying to use the size static member. it's a good thing that nightmare is gone I tell ye :-) up with sizeof, down with size Dan Williams wrote:I'm having a little trouble with typeof(). The D documentation says: "Typeof is a way to specify a type based on the type of an expression." That's fair enough, but in that case how do you DETECT the current type of an expression? I was hoping that either typeof would return something to tell me a current type, or that I could at the very least to typeof comparison checking such as if (typeof('c') == typeof(int)) - something like that in any case. However, the compiler keeps yelling that it expects a dot, and I'm really not sure how to do what I want. Things like typeof(a).sizeof work fine (by the way, why was size deprecated in favour of sizeof? To my mind, size is more fitting for a property, i.e. a.size, and sizeof for a function, i.e. sizeof(a). But never mind...) however the code examples on the D site are very sparse when it comes to typeof(), and some do not actually work at all. I guess I'm a little confused about the purpose of typeof(), as my initial logical assumption would be that it would check what type something is, and yet the documentation (keyword: "specify") makes me think that it's actually more like cast(). Which brings me to two questions: if typeof() is actually like cast(), why is it there? And how can I detect the type of a variable (or expression)? Sorry if this is a stupid question, but a search of the D newsgroups and a Google of the site did not reveal anything to help me.
Jun 30 2004
On Wed, 30 Jun 2004 14:17:21 -0700, Daniel Horn <hellcatv hotmail.com> wrote:I made a vector class with a static size member strange things happened when size was actually a PROPERTY... what should have been a compiler error turned into a runtime error... and other strange havoc resulted when trying to use the size static member. it's a good thing that nightmare is gone I tell ye :-) up with sizeof, down with sizeHmm... but say you now make a static class member called sizeof.. class A { static int sizeof; } void main() { A a = new A(); printf("%d\n",a.sizeof); } this compiles, runs and prints "0". Remove the "static int sizeof" and it compiles, runs and prints "4". Should this be allowed, should it be a compiler error? I think it should. ReganDan Williams wrote:-- Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/I'm having a little trouble with typeof(). The D documentation says: "Typeof is a way to specify a type based on the type of an expression." That's fair enough, but in that case how do you DETECT the current type of an expression? I was hoping that either typeof would return something to tell me a current type, or that I could at the very least to typeof comparison checking such as if (typeof('c') == typeof(int)) - something like that in any case. However, the compiler keeps yelling that it expects a dot, and I'm really not sure how to do what I want. Things like typeof(a).sizeof work fine (by the way, why was size deprecated in favour of sizeof? To my mind, size is more fitting for a property, i.e. a.size, and sizeof for a function, i.e. sizeof(a). But never mind...) however the code examples on the D site are very sparse when it comes to typeof(), and some do not actually work at all. I guess I'm a little confused about the purpose of typeof(), as my initial logical assumption would be that it would check what type something is, and yet the documentation (keyword: "specify") makes me think that it's actually more like cast(). Which brings me to two questions: if typeof() is actually like cast(), why is it there? And how can I detect the type of a variable (or expression)? Sorry if this is a stupid question, but a search of the D newsgroups and a Google of the site did not reveal anything to help me.
Jun 30 2004