"Common" in c

Posted on 2005-04-26
Last Modified: 2013-11-08
Is there  any sentence in c equivalent to the (fortran) "common" sentence?
Juan Carlos
Question by:juanc
    LVL 44

    Expert Comment

    no.  The closest to the concept is to create 'global' variables.

    LVL 16

    Expert Comment

    A little research suggests that 'extern struct' acts much the same in C as 'common' functions in FORTRAN.

    LVL 23

    Accepted Solution

    Nah, it's globals, kinda, but also externs, kinda.

    In Fortran, the compiler generates relative references to the COMMON area which are resolved by the linker.

    To get a similar working effect:
    * declare them all by themselves in a separate module
    * create a header file that references them with 'extern'

    Here's something I dug up from eight years ago:

    FILE * INIFile;          // Handle for input file
    FILE * OutFile;          // Hmm?
    int    InputEOF;         // Non-zero says end of input
    char   LineIn[256];      // Line from input file
    char   AppName[128];     // Name of application from section header in INIFile
    char   IniFilename[128]; // Filename from INI=
    char   IniSection[128];  // Section name from INI=
    char   IniLabel[128];    // Label from INI=
    char   StrFilename[128]; // Filename from string=
    long   StrOffset;        // Offset from string=
    int    StrLength;        // Length from string=

    corresponding .h
    extern FILE  *INIFile;
    extern FILE  *OutFile;
    extern int    InputEOF;
    extern char   LineIn[256];
    extern char   AppName[128];
    extern char   IniFilename[128];
    extern char   IniSection[128];
    extern char   IniLabel[128];
    extern char   StrFilename[128];
    extern long   StrOffset;
    extern int    StrLength;
    LVL 2

    Expert Comment

    look this links

    Labeled COMMON
    Fortran labeled COMMON can be emulated in C by using a global struct:

    Code  Example  11-13     Labeled COMMON  
     Fortran COMMON Definition
     C "COMMON" Definition


     extern struct block {

        float alpha;

        int num;


    extern struct block block_ ;

    main ()



      block_.alpha = 32.;

      block_.num += 1;




    Note that the external name established by the C routine must end in underscore to link with the block created by the Fortran program.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    The purpose of this article is to demonstrate how we can use conditional statements using Python.
    In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now