LONG_MAX in D

nobody nobody at mailinator.com
Thu Aug 17 17:17:44 PDT 2006


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.



More information about the Digitalmars-d mailing list