[starting a new thread] Damian,
We have numBits(type t) and numBytes(type t) that are defined on certain primitive types. We do not provide this functionality for the other types, I believe. See the online library documentation: http://chapel.cray.com/docs/latest/modules/standard/Types.html specifically: http://chapel.cray.com/docs/latest/modules/standard/Types.html#Types.numBits P.S. The thing that ".type" expression produces is a Chapel type. Chapel types, like 'param' variables/expressions, can be manipulated at compile time. The Types modules has a few functions on expressions besides what I mention above. Vass -------- Original Message -------- Subject: Equivalent of sizeof() for a variable of expression Date: Thu, 21 May 2015 09:37:08 +1000 From: Damian McGuckin <[email protected]> To: <[email protected]> Dear Thinkers, Already in Chapel, there is an attribute of any variable or expression called '.type', such that, given definitions like var vr : real(64); var vi : int(32); then vr.type or even (vi * 55.5).type returns a concept/value/thing which is real and so on. This allows for such usage as var t : vr.type; which defines 't' as being a real(64) variable. Is there an equivalent to C's sizeof for types and expressions? For example, and remembering that '.size' has already been commandeered for use with range and arrays to return the number of components or items in either a range or an array, I want to do something like // find out what the size of a variable is if vr.bits == 64 then { writeln("64 bit quantity"); } else { writeln("not 64-bits at all"); } or more precisely (yes Michael, took your advice) var r : real(64); var i : int(r.bits); var rsize : int(32) = r.bits >> 3; // divide by 8 .... memcpy(i, r, rsize); where memcpy is defined as a C function. I apologize if bits is meaningful in other contents. And it also begs the other question of whether one's brain, when in 'mode=Chapel', should think in terms of bits or bytes. Personally I prefer sizeof/typeof/bitsof but I can run with whatever. Now this time as I keep getting reminded, I did go fishing in README.* in doc/{release,}/technotes and could not find anything relevant. It might be there but I could not find it. If it is, then I need to go and start shopping for glasses. I also could not find this in the primary documentation. Also, as an aside, what other attributes of types beside '.type' are predefined. Regards - Damian P.S. And while we are at it, on a philsophical point, Is something as fundamental to a variable as say the absolute value of a number 'x', floating or integral, or even say its sign, given by a) attribute of the number, i.e. given by x.abs b) method applied to that number, i.e. given by x.abs() c) some function call abs(x : T) : T Not looking for a religious war here. Just some feedback. Pacific Engineering Systems International, 277-279 Broadway, Glebe NSW 2037 Ph:+61-2-8571-0847 .. Fx:+61-2-9692-9623 | unsolicited email not wanted here Views & opinions here are mine and not those of any past or present employer ------------------------------------------------------------------------------ One dashboard for servers and applications across Physical-Virtual-Cloud Widest out-of-the-box monitoring support with 50+ applications Performance metrics, stats and reports that give you Actionable Insights Deep dive visibility with transaction tracing using APM Insight. http://ad.doubleclick.net/ddm/clk/290420510;117567292;y _______________________________________________ Chapel-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/chapel-users
