1

I see the following code in HPUX C program:

   extern int fcntl __((int, int, ...));
   _LF_EXTERN int creat __((const char *, mode_t));

These lines are compiled using aCC.

Could somebody let me know the meaning of 2 underscores after fcntl and creat in the above code?

Matthieu M.
  • 287,565
  • 48
  • 449
  • 722
Chandu
  • 1,837
  • 7
  • 30
  • 51
  • 2
    I suspect this to be a macro function. Can you show the preprocessed version of this code? – mafso Aug 19 '14 at 12:24
  • 3
    The duplicates are wrong, but be it as it may. I've seen something similar e.g. in the readline library sourcecode to distinct between old-style declarations/definitions and prototypes. So, on a "modern" (not older than ~30 years) system, it will expand to `(int, int, ...)`, on old systems to `()`. HTH, just a shot in the dark, though. – mafso Aug 19 '14 at 12:30
  • The duplicates were indeed wrong. – Lightness Races in Orbit Aug 19 '14 at 12:32
  • It's probably defined as a macro. Look for `#define __` (with optional whitespace inserted) somewhere in header files included by that file. – Angew is no longer proud of SO Aug 19 '14 at 12:39

1 Answers1

6

This is most likely a macro that enables the use of the header with old, pre-ANSI C compilers.
The "old style" C function declarations didn't include parameter types.

I suspect its definition looks somewhat like this

#ifdef __STDC__
#define __(params) params
#else
#define __(params) ()
#endif 

I believe type-safe function prototypes is one of the first language features that C adopted from C++.
And the fact that I remember this makes me feel very, very old.

molbdnilo
  • 64,751
  • 3
  • 43
  • 82