Modules and namespaces

D

deltaquattro

Hi,

I'm currently learning C++ and I would like to ask you the difference
between Fortran 95 modules and C++ namespaces. To me they look the
same, except for the scope operator :: in C++, which is a bit more
convenient than F95 rename operator =>, to avoid name clashes. Thank
you,

greetings,

deltaquattro
 
P

Pierre Asselin

In comp.lang.fortran deltaquattro said:
I'm currently learning C++ and I would like to ask you the difference
between Fortran 95 modules and C++ namespaces. To me they look the
same, except for the scope operator :: in C++, which is a bit more
convenient than F95 rename operator =>, to avoid name clashes. Thank

C++ namespaces are extendible, Fortran modules aren't. Once
you reach the "end module" statement, that's the end of it.
In C++ you can reopen the namespace scope and pile more stuff
into it.

That's one difference. I would be surprised if there aren't many
more. Analogies between Fortran and C++ (or C) are often more
misleading than helpful, so beware.
 
A

Arjen Markus

C++ namespaces are extendible, Fortran modules aren't. Once
you reach the "end module" statement, that's the end of it.
In C++ you can reopen the namespace scope and pile more stuff
into it.

That's one difference. I would be surprised if there aren't many
more. Analogies between Fortran and C++ (or C) are often more
misleading than helpful, so beware.

Well, you can join Fortran modules into a new module:

module composite
use module_a
use module_b
...
end module

The new module has all the facilities of the individual ones.

(And interfaces can be defined piecewise as well).

I am not familiar enough with C++'s namespaces to comment on them.

My mental picture of modules is that they do not induce a hierarchy,
but rather import facilities into the current scope and blend them
in seemlessly. I do not think namespaces in C++ work just like that.

Regards,

Arjen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top