Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Byte amount in the array index 2

Status
Not open for further replies.

GerritGroot

Technical User
Nov 3, 2006
291
ES
Hi,

I've got a question about the byte amount of the array indices themselves.

Imagine that I define:

Code:
INTEGER, PARAMETER :: I8B=SELECTED_INT_KIND(18)
! And
INTEGER(KIND=I8B), PARAMETER :: mx4b=2**32
INTEGER(KIND=I8B), DIMENSION(mx4b) :: MyArray

Now, MyArray is an array of integers, each of them 8bytes long, but what kind of integer is used for the indices of MyArray?

Are the indices of MyArray than defined by an 8byte integer?
(I got strange overflow errors when running)

Is there a way to define this? Or is this fixed?

Thanks,

Gerrit
 
The problem is sign extension. See what the following gives you
Code:
    program bignum

    implicit none
    INTEGER, PARAMETER :: I8B=SELECTED_INT_KIND(18)
    integer(kind=I8B) nbig
    integer n
    
    do n = 30, 33
       nbig = 2 ** n
       print '(I2,1X,Z16)', n, nbig
    end do

    end program bignum
I get
Code:
30         40000000
31 FFFFFFFF80000000
32                1
33                2
However, if you change 2 to 2_I8B, you get
Code:
30         40000000
31         80000000
32        100000000
33        200000000
You would need an INTEGER(KIND=I8B) for the index but make sure that any constants used in the indices are suffixed by _I8B otherwise they will revert to 4 byte integers where the biggest number is 2**31.

 
Thanks xwb,

Is that suffix _I8B a standard method? (once I8B s defined of course)

Anyway, as you didn't make an array, it still doesn't say anything about the bit amount of x under the definition DIMENSION(x), does it?
 
Is that suffix _I8B a standard method? (once I8B s defined of course){/quote]

yes it is

Anyway, as you didn't make an array, it still doesn't say anything about the bit amount of x under the definition DIMENSION(x), does it?

Your example is OK if you add _I8B :

Code:
INTEGER, PARAMETER :: I8B=SELECTED_INT_KIND(18)
! And
INTEGER(KIND=I8B), PARAMETER :: mx4b=2_I8B**32
INTEGER(KIND=I8B), DIMENSION(mx4b) :: MyArray

Of course, to access the elements of the array MyArray, you need an index variable declared INTEGER(KIND=I8B) or an integer value with the suffix _I8B


François Jacq
 
Thanks both! And sorry for being a bit slow on the uptake :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top