Thread overview | |||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
August 17, 2006 LONG_MAX in D | ||||
---|---|---|---|---|
| ||||
Hi again, What is the best way to compute LONG_MAX in D? (as of limits.h) size_t / 2? Luís |
August 17, 2006 Re: LONG_MAX in D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Luís Marques | 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ís Properties 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. |
August 17, 2006 Re: LONG_MAX in D | ||||
---|---|---|---|---|
| ||||
Posted in reply to nobody | nobody wrote: > long val; > long.max // works > val.max // also works LONG_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 |
August 18, 2006 Re: LONG_MAX in D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Luís Marques | Luís Marques wrote: > nobody wrote: >> long val; >> long.max // works >> val.max // also works > > LONG_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. 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; >> 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? 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. |
August 18, 2006 Re: LONG_MAX in D | ||||
---|---|---|---|---|
| ||||
Posted in reply to nobody | 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
|
August 18, 2006 Re: LONG_MAX in D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Luís Marques | 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
|
August 18, 2006 Re: LONG_MAX in D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Luís Marques | Luís Marques wrote:
> 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
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. :-)
|
August 18, 2006 Re: LONG_MAX in D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Luís Marques | 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 works
>
> LONG_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
|
August 18, 2006 Re: LONG_MAX in D | ||||
---|---|---|---|---|
| ||||
Posted in reply to nobody | 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 |
August 18, 2006 Re: LONG_MAX in D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Luís Marques | Luís Marques wrote: > nobody wrote: >> long val; >> long.max // works >> val.max // also works > > LONG_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). Why would you want this in a D program? You can probably find what you want in std.stdint. > 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? 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. |
Copyright © 1999-2021 by the D Language Foundation