Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How exactly do pointers in Fortran differ from C/C++ pointers?

It might be useful to have both C/C++ programmers and Fortran programmers compare and contrast pointers in these two languages.

In trying to explain to C/C++ programmers how Fortran pointers differ, I usually say pointers to functions or subroutines do not exist. I then try to make the argument that Fortran pointers are more "higher-level", but the details are fuzzy.

What exactly is the difference?

like image 281
ShanZhengYang Avatar asked Sep 18 '26 01:09

ShanZhengYang


1 Answers

As Mark says, pointers to functions and subroutines certainly do exist in Fortran. The differences are:

  • In C, pointers are just an address whereas in Fortran, a pointer can have additional information such as array bounds and strides, which is why an explicit interface is required when declaring a pointer dummy argument
  • In C, you have to explicitly dereference a pointer, whereas in Fortran the dereferencing is automatic (except in contexts where a pointer is required)
  • In C, there are no assumptions about aliasing, whereas in Fortran you're only allowed to point to things that have the TARGET attribute
like image 148
Steve Lionel Avatar answered Sep 19 '26 18:09

Steve Lionel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!