PGI User Forum
 SearchSearch   MemberlistMemberlist     RegisterRegister   ProfileProfile    Log inLog in 

CUDA-x86.

Issue with Character Arrays

 
Post new topic   Reply to topic    PGI User Forum Forum Index -> Debugging and Profiling
View previous topic :: View next topic  
Author Message
FTA12



Joined: 02 Apr 2014
Posts: 1

PostPosted: Wed Apr 02, 2014 11:30 pm    Post subject: Issue with Character Arrays Reply with quote

Hi all,

I have been encountering an error with a FORTRAN program that I was able to narrow down to possibly a compiler issue. Here is a short example code that throws the error:

Code:

program test
implicit none

character(len=12) :: test1(2),test2(2)

test1=(/'1234567890','123456789'/)
test2=(/'123456789','1234567890'/)

print *,'Test 1 ',test1
print *,'Test 2 ',test2


On my machine, I get the following output:

Code:

Test 1 1234567890 123456789
Test 2 123456789 123456789


Now, maybe there is some obscure FORTRAN rule (not the rarest thing in the world) that causes this to occur--that when I have a character array with more than one element and the elements are of different length, the the final element's trailing 0 is removed.

I use these arrays as flags during loops, so I am luckily able to use test1 instead of test2. For rigor, I use gfortran to compile the same program and get this output when running:

Code:

Test 1 1234567890 123456789
Test 2 123456789 1234567890


Anyone have any suggestions or experiencing the same problem? For the record, I am using pgf90 11.10-0.
Back to top
View user's profile
cparrott



Joined: 02 May 2011
Posts: 146

PostPosted: Thu Apr 03, 2014 10:23 am    Post subject: Reply with quote

Hi,

I would need to check with the Fortran language experts here, but I suspect that the strings of different character lengths may be undefined behavior.

If you add a space to the end of the first string of test2, the PGI output will do what you expect:

Code:

cparrott ~ $ pgf90 -o testout testout.f90
cparrott ~ $ ./testout
 Test 1 1234567890  123456789
 Test 2 123456789   1234567890


For what it's worth, gfortran 4.8.2 now flags your example with an error:

Code:

cparrott ~ $ gfortran -o testout testout.f90
testout.f90:6.21:

test1=(/'1234567890','123456789'/)
                     1
Error: Different CHARACTER lengths (10/9) in array constructor at (1)
testout.f90:7.20:

test2=(/'123456789','1234567890'/)
                    1
Error: Different CHARACTER lengths (9/10) in array constructor at (1)


Hope this helps.

Best regards,

+chris
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    PGI User Forum Forum Index -> Debugging and Profiling All times are GMT - 7 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © phpBB Group