Viktor的Fortran手记之三 风格、选择与效果

Viktor posted @ Jul 30, 2008 05:35:40 AM in FORTRAN with tags fortran Viktor , 2652 阅读

 

implicit none

 

 

以绕过I--N规则。(呵呵,一句名言,"God is Real until claimed as Integer. "嗯……然则min一类习惯的名字就要小心了……)

  • 在subroutine和function里,所有的local var.都默认是STORE的。什么意思呢?比如说,
    function xxoo(...)
        ...
        integer :: ooxx = 1
        ...

        ooxx = ooxx + 1
       
        ...
    end function xxoo

只有第一次xxoo(...)的时候,ooxx才是1.以后就会变成2,3,4,5,……如果要避免这个副作用,就得写

 

function xxoo(...)
    ...
    integer :: ooxx
    ...

    ooxx = 1 !Here to initialize ooxx
   
    ...
end function xxoo

C里面可是默认全都毁掉的,不要混了……

  • 有的地方说inout要写成in out,goto要写成go to,然则得视编译器而定。
  • 注释写感叹号,续行就用&,从第9列写起(兼容Tab和古典FORTRAN格式)。第5列(按一个Tab)写行号的个位。第6列一定要让它空着!除非续行的时候,可以写&。需要兼容性的时候,这是必须的。
  • 虽然新Fortran支持长名字,然则还是写6字符以内的短名比较好。小猫见过hankei和takasa之类诡异的名字……
  • 循环里严格禁止改循环变量:
    do i = 1, n
        i = exFlag !Compile error!
        ...
    end do
  • 最应该记住的,是调用function的时候得事先在块中声明……
  • module是个好东西,声明什么的都可以往里装。还可以用它实现运算符重载和多态函数……C++用的是类,这里用的就是TYPE……
Avatar_small
10th Question Paper 说:
Feb 14, 2023 03:07:24 PM

The Board of Secondary Education This year, SSC Question Paper 2024 was successfully organized for all eligible candidates who wish to appear for the test. A large number of individuals have registered for the 10th class Board 2024 and have finished their written exam. 10th Question Paper 2024 All students are now eagerly awaiting the official announcement of the SSC Final Question Paper 2024. All 10th-grade students may now get their SSC Question Paper 2024, topic by subject Paper 2024 Wise Download here.


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter