• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 267
  • Last Modified:

"Common" in c

Is there  any sentence in c equivalent to the (fortran) "common" sentence?
thanks
Juan Carlos
0
juanc
Asked:
juanc
1 Solution
 
Arthur_WoodCommented:
no.  The closest to the concept is to create 'global' variables.

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

Paul
0
 
cookreCommented:
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:

globals.c
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;
0
 
ultrapascalCommented:
look this links
http://www.ictp.trieste.it/~manuals/programming/sun/fortran/prog_guide/11_cfort.doc.html#9221


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
 
 COMMON /BLOCK/ ALPHA,NUM

  ...


 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.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now