100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Programming

Interfacing Fortran with C

Learn to safely call C functions from Fortran and expose Fortran routines to C using the standardized iso_c_binding module.

Practical FortranIntermediate11 min readJul 10, 2026
Analogies

Introduction to the ISO_C_BINDING Module

Modern Fortran defines a standardized way to interoperate with C through the intrinsic module iso_c_binding, introduced in Fortran 2003. It supplies portable kind parameters such as c_int, c_double, and c_float that guarantee a Fortran variable has exactly the same binary representation as the corresponding C type on the target platform, replacing the old, non-portable practice of guessing that a Fortran integer happened to match a C int. Without iso_c_binding, calling a C library from Fortran (or vice versa) relies on compiler-specific conventions that can silently break when you switch compilers or platforms.

🏏

Cricket analogy: Like agreeing on ICC's official pitch and ball specifications before an international match, so a bowler trained in Australia and a batter trained in India both know exactly what to expect, rather than each team guessing the other's local ground rules.

Calling C Functions from Fortran

To call a C function from Fortran, you write an explicit interface block declaring the function with the bind(c, name='c_function_name') attribute, matching each C parameter's type to its iso_c_binding equivalent (for example a C double* typically corresponds to a Fortran real(c_double), value or a pointer target depending on whether C expects a value or an address). The value attribute on a dummy argument is essential when the C function expects to receive an argument by value rather than by reference, since Fortran otherwise passes everything by reference by default, which would hand the C function a pointer where it expected a plain number.

🏏

Cricket analogy: Like an overseas fast bowler joining a domestic franchise: the coaching staff writes an explicit dossier translating his exact grip, run-up length, and release point into terms the local team understands, rather than assuming his technique needs no translation.

fortran
! Fortran side: calling C's sqrt() from libm via an explicit interface
module c_math
  use, intrinsic :: iso_c_binding
  implicit none
  interface
     function c_sqrt(x) bind(c, name='sqrt') result(res)
       import :: c_double
       real(c_double), value :: x
       real(c_double) :: res
     end function c_sqrt
  end interface
end module c_math

program call_c
  use c_math
  implicit none
  real(c_double) :: y
  y = c_sqrt(2.0_c_double)
  print *, 'sqrt(2) via C =', y
end program call_c

Exposing Fortran to C: the bind(c) Attribute

The interoperability is symmetric: a Fortran subroutine or function can be made callable from C by adding bind(c, name='...') to its own declaration, which fixes its external symbol name to match exactly what the C linker expects (Fortran compilers otherwise mangle names with case-folding and compiler-specific decoration). Derived types intended to cross the boundary must be declared with the bind(c) attribute too, so their member layout matches a C struct field-for-field with no hidden padding or descriptor overhead that a plain Fortran derived type (which may carry array descriptors) would otherwise introduce.

🏏

Cricket analogy: Like a domestic player being registered under one fixed, official name on the international team sheet so overseas commentators and scorers can identify him unambiguously, instead of each broadcaster using a different local nickname.

Mixing a plain (non-bind(c)) Fortran derived type into a C interface is a common and dangerous mistake: ordinary Fortran derived types can carry compiler-specific hidden metadata (for allocatable components, type-bound procedures, or array descriptors) that has no equivalent in a C struct, so the two languages will disagree about the memory layout and corrupt data silently. Always declare cross-language types with bind(c) and stick to interoperable component types.

Practical Workflow and Tooling

In practice, mixed Fortran/C projects are built by compiling each language's source with its own compiler and linking the resulting object files together (for example gfortran and gcc both produce standard object files that a single linker invocation can combine), often orchestrated by CMake's Fortran/C language support or a hand-written Makefile that tracks both toolchains. Because C has no notion of Fortran's array descriptors, arrays crossing the boundary are normally passed as a plain pointer to contiguous data (real(c_double), dimension(*) or type(c_ptr)) alongside an explicit integer size argument, since C has no built-in way to ask an incoming pointer how many elements it points to.

🏏

Cricket analogy: Like a franchise fielding both a local domestic scoring system and an international ICC scoring feed, with a dedicated liaison officer who reconciles the two into one official scoreboard, rather than assuming they merge automatically.

When passing a Fortran array to C, always pass its element count as a separate explicit integer(c_int) argument. Unlike a Fortran array (which the compiler tracks bounds for internally), a C pointer carries no built-in size information, so the receiving C function has no way to know how many elements are safely accessible unless told.

  • iso_c_binding provides portable kind parameters (c_int, c_double, etc.) guaranteeing exact binary compatibility with C types.
  • bind(c, name='...') on an interface block lets Fortran call an existing C function with a fixed, predictable symbol name.
  • The value attribute is required on dummy arguments when the C function expects an argument passed by value, not by reference.
  • bind(c) on a derived type declaration (or the Fortran side of a symbol) ensures the memory layout and name match exactly what C expects.
  • Mixing ordinary (non-interoperable) Fortran derived types into a C interface risks silent memory-layout mismatches.
  • Arrays crossing the Fortran/C boundary are passed as raw pointers plus an explicit size argument, since C has no array descriptors.
  • Mixed-language projects are typically built by compiling each language separately and linking the object files together, often via CMake.

Practice what you learned

Was this page helpful?

Topics covered

#Programming#FortranStudyNotes#InterfacingFortranWithC#Interfacing#Fortran#ISO#BINDING#StudyNotes#SkillVeris#ExamPrep

Frequently Asked Questions

21 categories · pick one to explore

Where can I get free study notes for programming and tech subjects?
SkillVeris offers completely free study notes covering programming and tech subjects, with no signup fees or paywalls. The notes are structured by course and topic, written for quick understanding, and enriched with the Learn Through Hobbies analogy method, so you can revise concepts through cricket, music, gaming, cooking and more.
Are SkillVeris study notes good for exam revision?
Yes, the study notes are designed for efficient revision: each topic answers its heading immediately, keeps explanations concise, and links to related glossary terms and cheat sheets. Students preparing for university exams or certification tests use them as quick revision notes because they distil concepts without the padding of full textbooks.
What subjects do the free study notes cover?
The study notes span the platform's main domains, including AI and machine learning, Python and programming, web development, DevOps, cloud, security and databases. Coverage mirrors the 37 live courses, so notes exist for the topics you are actually studying, and new note sets are added as courses launch.
How are SkillVeris study notes different from regular textbooks?
The notes are answer-first, concise and free, whereas textbooks are long and often expensive. Each section explains one concept directly, then reinforces it through selectable hobby analogies like cricket or cooking. Notes also cross-link to the glossary, blog and cheat sheets, letting you jump to related material instantly instead of flipping pages.
Can I use the developer study material without creating an account?
The study notes are free to access, and SkillVeris does not charge anything for its developer study material at any point. Browsing notes is straightforward from the Study Notes section, and if you want progress tracking, certificates and AI Mentor conversations tied to your learning, a free account unlocks those extras.
Do the study notes explain concepts with analogies?
Yes, this is a signature SkillVeris feature. Study notes use the Learn Through Hobbies method, explaining technical concepts through analogies from twelve domains including cricket, music, gaming, photography, travel, movies, fitness, chess, cooking, finance, business and sports. You can switch the analogy domain instantly to whichever hobby makes the concept click.
Are the revision notes suitable for last-minute exam preparation?
Yes, revision notes on SkillVeris work well for last-minute preparation because every section states the answer in its first sentences, so skimming is genuinely effective. Pair them with the relevant cheat sheet for formulas and syntax, and use the glossary for any unfamiliar term you meet while cramming.
Is there free study material for AI and machine learning?
Yes, SkillVeris provides free study notes across its AI and ML catalogue, covering Python for AI, deep learning frameworks like PyTorch and TensorFlow, Hugging Face Transformers, Large Language Models, RAG, AI agents and MLOps. All of it is free, making it a strong resource for Indian students and global learners alike.
Can beginners understand the study notes, or are they for experts?
Beginners can absolutely use them. The notes are written in plain language, define terms as they appear, and lean on hobby analogies to make abstract ideas concrete. Difficulty scales with the underlying course level, so beginner-course notes stay gentle while advanced-course notes go deeper, and the glossary supports you throughout.
How do study notes connect with SkillVeris courses?
Study notes are organised by course and topic, so they map directly to the structured courses and their 24–40-lesson curriculum. Many learners study a lesson first, then use the matching notes for revision before module assessments and the final exam, where 80 percent is required to pass and earn the certificate.
Are there study notes for Python specifically?
Yes, Python is well covered through notes tied to the Python-focused courses, including Python for AI and ML. Topics span fundamentals through applied machine learning usage. You can reinforce the notes with Python practice in Code Lab, which runs code in your browser with no installation required.
Do the study notes include code examples?
Yes, study notes include code examples wherever a concept is best shown in code, alongside explanations, key points and analogies. Reading a snippet in the notes and then reproducing it yourself in Code Lab is an effective loop, since Code Lab lets you run code in the browser across six languages.
How often is new study material added to SkillVeris?
Study material grows alongside the course catalogue. Whenever new courses join the platform's 37 live courses, matching study notes, glossary entries and cheat sheets are added so the resources stay in sync. Existing notes are also refined over time, so it is worth revisiting topics you studied earlier.
Can I use SkillVeris notes to prepare for technical interviews?
Yes, the notes make excellent interview revision because they compress each concept into direct, answer-first explanations, which mirrors how you should answer interview questions. Combine them with the SkillVeris interview questions feature, which includes readiness scoring, to test whether your revision has actually made you interview-ready.
Are the study notes mobile-friendly for studying on the go?
Yes, the study notes are built to load fast and read comfortably on mobile devices, so you can revise during a commute or between classes. Sections are short and answer-first, which suits small screens, and analogy switching works on mobile too, letting you study anywhere without carrying books.
What is the difference between study notes and cheat sheets?
Study notes explain concepts in depth with context, examples and analogies, making them ideal for learning and revision. Cheat sheets are compact quick-reference summaries of syntax, commands and key facts, ideal once you already understand a topic. Most learners study the notes first, then keep the cheat sheet handy while coding.
Do study notes help if I am stuck on a course lesson?
Yes, reading the matching study notes often clarifies a lesson because the same concept is explained from a different angle, frequently with a different analogy. If you are still stuck, ask the AI Mentor, which answers 24/7 at Quick, Detailed or Deep-dive depth until the idea genuinely makes sense.
Is there free study material for DevOps and cloud topics?
Yes, SkillVeris carries free study notes for DevOps and cloud topics as part of its coverage across 37 live courses. The material suits learners following the DevOps Engineer or Cloud Engineer paths, and it links to related glossary terms and cheat sheets so you can revise the whole toolchain in one place.
Can school or college students in India use these notes for projects?
Yes, students across India and worldwide use SkillVeris notes for coursework, projects and exam preparation, and everything is free, which matters for student budgets. The notes explain concepts clearly enough to cite in project reports, and Code Lab lets you prototype the project code directly in your browser.
How should I combine study notes with other SkillVeris resources?
A proven loop: learn from a course lesson, revise with the matching study notes, look up unfamiliar terms in the glossary, keep the cheat sheet open while practising in Code Lab, and quiz yourself with interview questions. The AI Mentor fills any remaining gaps 24/7, at whatever depth you need.

What Learners Say

Real journeys from the SkillVeris community — swipe for more.

SkillVeris taught me Python through Cricket. Now I’m building real projects and feeling confident!
Arjun S. · B.Tech Student
The best platform for hobby-based learning. Concepts finally stick.
Priya R. · Data Analyst
I went from zero coding to a portfolio of projects — all by learning through my love for gaming. Landed my first internship!
Kabir M. · CS Undergraduate
Trending Topics50 popular tags — tap to explore
Trending CoursesAll 37 free courses — tap to browse