digitalmars.D - LONG_MAX in D
- =?ISO-8859-1?Q?Lu=EDs_Marques?= (4/4) Aug 17 2006 Hi again,
- nobody (14/20) Aug 17 2006 Properties for Integral Types
- =?ISO-8859-1?Q?Lu=EDs_Marques?= (8/17) Aug 17 2006 LONG_MAX is "Maximal value which can be stored in a long int variable"
- nobody (24/43) Aug 17 2006 Conditional Compilation
- =?ISO-8859-1?Q?Lu=EDs_Marques?= (4/12) Aug 17 2006 Well, I don't see much point in that, over "size_t.max / 2" :-)
- nobody (5/19) Aug 17 2006 I can certainly see why you might prefer size_t.max / 2. I would persona...
- =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= (5/13) Aug 18 2006 Effectively limiting yourself to the Intel archs, of course...
- Unknown W. Brackets (8/30) Aug 17 2006 Do you just want to know the maximum value stored in a signed size_t?
- Don Clugston (5/24) Aug 18 2006 Why would you want this in a D program?
- =?ISO-8859-1?Q?Lu=EDs_Marques?= (4/5) Aug 18 2006 I'm implementing an API which uses that value. More specifically, I
- =?ISO-8859-1?Q?Lu=EDs_Marques?= (3/7) Aug 17 2006 I meant size_t.max / 2, which I'm currently using.
Hi again, What is the best way to compute LONG_MAX in D? (as of limits.h) size_t / 2? Luís
Aug 17 2006
Luís Marques wrote:Hi again, What is the best way to compute LONG_MAX in D? (as of limits.h) size_t / 2? LuísProperties for Integral Types http://digitalmars.com/d/property.html .init initializer (0) .max maximum value .min minimum value long val; long.max // works val.max // also works Also wanted to suggest that D.learn might be a more responsive place to ask this sort of question. This NG seems to be more meta-D than anything-D (while both happen). You will want to come back here to see the next mega wave of discussion about getting import to work, whether consts are good or evil, how auto should work and pretty much anything related to the way classes are implemented.
Aug 17 2006
nobody wrote:long val; long.max // works val.max // also worksLONG_MAX is "Maximal value which can be stored in a long int variable" (in C) and differs with platforms (e.g. 32 bit, 64 bit). long.max is fixed for a 64-bit integer.Also wanted to suggest that D.learn might be a more responsive place to ask this sort of question. This NG seems to be more meta-D than anything-D (while both happen). You will want to come back here to see the next mega wave of discussion about getting import to work, whether consts are good or evil, how auto should work and pretty much anything related to the way classes are implemented.Perhaps you are right, but I felt that this isn't a question about learning the language itself and that D.learn might not be the best resource. What are the boundaries? Luís
Aug 17 2006
Luís Marques wrote:nobody wrote:Conditional Compilation http://digitalmars.com/d/version.html Predefined Versions X86 Intel and AMD 32 bit processors X86_64 AMD and Intel 64 bit processors I am remembering that when I have used C on my 32 bit machines I am fairly sure a long long was 64 bits and a long int was 32. I went looking and found an old header file that assures me long long is 8 bytes. I can only assume long int is 4 bytes for a 32 bit machine. Assuming you want to define an equivalent using D then it would be done as follows: version(X86) const int LONG_MAX = int.max; version(X86_64) const long LONG_MAX = long.max; Another way to define LONG_MAX conditionally is explained in the Static If Condition of the above page: static if(size_t.sizeof == 4) const int LONG_MAX = int.max; static if(size_t.sizeof == 8) const long LONG_MAX = long.max;long val; long.max // works val.max // also worksLONG_MAX is "Maximal value which can be stored in a long int variable" (in C) and differs with platforms (e.g. 32 bit, 64 bit). long.max is fixed for a 64-bit integer.Honestly I have no idea. Most of what I said was completely my own rather short observation (I have not been around very long either). I can say I have never seen anyone complain.Also wanted to suggest that D.learn might be a more responsive place to ask this sort of question. This NG seems to be more meta-D than anything-D (while both happen). You will want to come back here to see the next mega wave of discussion about getting import to work, whether consts are good or evil, how auto should work and pretty much anything related to the way classes are implemented.Perhaps you are right, but I felt that this isn't a question about learning the language itself and that D.learn might not be the best resource. What are the boundaries?
Aug 17 2006
nobody wrote:Another way to define LONG_MAX conditionally is explained in the Static If Condition of the above page: static if(size_t.sizeof == 4) const int LONG_MAX = int.max; static if(size_t.sizeof == 8) const long LONG_MAX = long.max;Well, I don't see much point in that, over "size_t.max / 2" :-) (ah yes, now I notice that I forgot the ".max") Luís
Aug 17 2006
Luís Marques wrote:nobody wrote:I can certainly see why you might prefer size_t.max / 2. I would personally use version statements with brackets if I were defining much more (LONG_MIN for example since size_t.min is 0). Anyway you can't say "nobody" warned you! I just pointed out the options. :-)Another way to define LONG_MAX conditionally is explained in the Static If Condition of the above page: static if(size_t.sizeof == 4) const int LONG_MAX = int.max; static if(size_t.sizeof == 8) const long LONG_MAX = long.max;Well, I don't see much point in that, over "size_t.max / 2" :-) (ah yes, now I notice that I forgot the ".max") Luís
Aug 17 2006
nobody wrote:Assuming you want to define an equivalent using D then it would be done as follows: version(X86) const int LONG_MAX = int.max; version(X86_64) const long LONG_MAX = long.max;Effectively limiting yourself to the Intel archs, of course... See http://www.prowiki.org/wiki4d/wiki.cgi?DocComments/Version size_t sounds more useful. --anders
Aug 18 2006
Do you just want to know the maximum value stored in a signed size_t? Isn't that ptrdiff_t.max? But if you don't know that, how is it useful? (I mean, if you're not using that type to store it I hardly understand what use the number is...) D.learn is for learning the language, D is for talking about the language. As far as I understand. I'd ask "how do I?" questions in D.learn, but that's just me. -[Unknown]nobody wrote:long val; long.max // works val.max // also worksLONG_MAX is "Maximal value which can be stored in a long int variable" (in C) and differs with platforms (e.g. 32 bit, 64 bit). long.max is fixed for a 64-bit integer.Also wanted to suggest that D.learn might be a more responsive place to ask this sort of question. This NG seems to be more meta-D than anything-D (while both happen). You will want to come back here to see the next mega wave of discussion about getting import to work, whether consts are good or evil, how auto should work and pretty much anything related to the way classes are implemented.Perhaps you are right, but I felt that this isn't a question about learning the language itself and that D.learn might not be the best resource. What are the boundaries? Luís
Aug 17 2006
Luís Marques wrote:nobody wrote:Why would you want this in a D program? You can probably find what you want in std.stdint.long val; long.max // works val.max // also worksLONG_MAX is "Maximal value which can be stored in a long int variable" (in C) and differs with platforms (e.g. 32 bit, 64 bit).long.max is fixed for a 64-bit integer.Many things like this have been posted there in the past. It's not so much a newbies forum as a "how can I do xxx" forum.Also wanted to suggest that D.learn might be a more responsive place to ask this sort of question. This NG seems to be more meta-D than anything-D (while both happen). You will want to come back here to see the next mega wave of discussion about getting import to work, whether consts are good or evil, how auto should work and pretty much anything related to the way classes are implemented.Perhaps you are right, but I felt that this isn't a question about learning the language itself and that D.learn might not be the best resource. What are the boundaries?
Aug 18 2006
Don Clugston wrote:Why would you want this in a D program?I'm implementing an API which uses that value. More specifically, I actually need to implement a function which returns LONG_MAX (it's the spec).
Aug 18 2006
Luís Marques wrote:Hi again, What is the best way to compute LONG_MAX in D? (as of limits.h) size_t / 2?I meant size_t.max / 2, which I'm currently using. Luís
Aug 17 2006