Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

What is the difference between char() and achar()?

496 views
Skip to first unread message

Peng Yu

unread,
May 26, 2013, 5:52:12 PM5/26/13
to
Hi,

The following fortran programs give identical results. I can not see
what the difference is between char() and achar() in the manual. Does
anybody know what the difference is? Thanks.

~/linux/test/fortran/lang/f90/intrinsic$ cat char/main.f90
program main
implicit none
print *, char(97)
end program

~/linux/test/fortran/lang/f90/intrinsic$ cat achar/main.f90
program main
implicit none
print *, achar(97)
end program

Regards,
Peng

Dan Nagle

unread,
May 26, 2013, 6:57:40 PM5/26/13
to
Hi,

On 2013-05-26 21:52:12 +0000, Peng Yu said:

> The following fortran programs give identical results. I can not see
> what the difference is between char() and achar() in the manual. Does
> anybody know what the difference is? Thanks.

achar/iachar convert between ascii characters and ascii character codes.
char/ichar convert between default characters and default character codes.

Most compilers use ascii as default, so the manual won't waste
a lot of ink distinguishing the two. :-)

--
Cheers!

Dan Nagle

Richard Maine

unread,
May 26, 2013, 7:04:15 PM5/26/13
to
Peng Yu <peng...@gmail.com> wrote:

> The following fortran programs give identical results. I can not see
> what the difference is between char() and achar() in the manual. Does
> anybody know what the difference is?

On systems that use ASCII character encoding, there is no difference.
That's the case for most systems. Where you will see a difference is on
systems that do *NOT* use ASCII as their default character encoding
(notably IBM mainframes and their ilk).

On those systems achar still uses the ASCII encoding, but char uses the
compiler's default encoding.

Thus achar is more portable in the sense that achar(97) is always a
lower case "a" on all systems. Char(97) will be the same on ASCII
systems, but could in principle be different on other systems.

There are applications for char, but mostly I recommend achar as
achieving what is most commonly desired in the most portable manner.

That being said, many codes willl never end up running on a machine
where it makes a difference.

--
Richard Maine
email: last name at domain . net
domain: summer-triangle

William Clodius

unread,
May 26, 2013, 7:13:29 PM5/26/13
to
For the vast majority of current Fortran processors there is no
difference for those characters in the standard character set. A few
computers still use an EBCDIC representation for the standard character
set. On those CHAR and ACHAR differ. Because of that ACHAR is the more
portable way of specifying characters from the standard character set.
0 new messages