Function Prototype - different argument names

C

cybernerdsx2

Hi,

I notice a function prototype being declared as following:

FileStream.h
=========
extern void openFile(char *__ident, int __option);

But, in the function declaration part shown as following:
FileStream.c
=========
void openFile(char *ident, int option)
{
...
}

Why is that the "__" prefix for "ident" and "option" required?

Rgds,

Mike
 
M

Mohan

cybernerdsx2 said:
Hi,

I notice a function prototype being declared as following:

FileStream.h
=========
extern void openFile(char *__ident, int __option);

But, in the function declaration part shown as following:
FileStream.c
=========
void openFile(char *ident, int option)
{
...
}

Why is that the "__" prefix for "ident" and "option" required?
parameter names in the function prototype are not mandatory and it can
have different names. i.e., it could be
extern void openFile(char *, int );
or
extern void openFile(char *idnt, int opt);

the usage of prefix '__' in variable names is not recommended as it is
inteded to use by the compiler for internal purpose.

--Mohan
 
M

Mohan

Mohan said:
parameter names in the function prototype are not mandatory and it can
have different names. i.e., it could be
extern void openFile(char *, int );
or
extern void openFile(char *idnt, int opt);

the usage of prefix '__' in variable names is not recommended as it is
inteded to use by the compiler for internal purpose.
Anyway in the prototype the paramenter names are ignored by the
compiler, it is just required to be a valid identifier.
 
C

Chris Torek

I notice a function prototype being declared as following:

FileStream.h
=========
extern void openFile(char *__ident, int __option);

But, in the function declaration part shown as following:
FileStream.c
=========
void openFile(char *ident, int option)
{
...
}

Why is that the "__" prefix for "ident" and "option" required?

They are not only not required, they are also a *bad* idea, with
one exception.

As far as the C standards are concerned, there are only two kinds
of programmers in the world: ones like me, who write the compilers
for you -- we are called "implementors" -- and ones like you, who
use the compilers we write.

Suppose I, as an implementor, am working on the file that I will
provide as <string.h>. In this file, I write:

char *strcpy(char *restrict dst, const char *restrict src);

Now you, as the user of my <string.h>, do this:

/* this is my module that does some funny stuff with times */
#define dst 1 /* compile in support for Daylight Saving Time */

#include <string.h> /* I need some functions from here */

You defined "dst" as 1, and then you included my (implementor's)
<string.h>, which -- in my implementation at least -- is just an
ordinary file with ordinary C rules applied. So the line I wrote
now reads, to the compiler, as:

char *strcpy(char *restrict 1, const char *restrict src);

and you get a "syntax error".

This is my fault: as an implementor, I *must* allow you to "#define
dst" however you like. So I *cannot* use that name.

If I want to use names in my <string.h> prototypes, what can I do?

The answer is: I can use names that, according to the C standands,
*you* must *not* use. Those names include any names that start
with double underscore, or underscore followed by an uppercase
letter. So *I* can use:

char *strcpy(char *restrict __dst, const char *restrict _SRC);

and thus be sure that I did not use any of "your" names. These
names are "my" names: names reserved to me.

If you use any of my names, the problem is yours, not mine. You
stick to your names, and I stick to mine, and everything will be
just fine.

(The other alternative here is that I can just write the prototypes
with no names at all. But at some point, I have to write various
internal functions, e.g., to implement parts of fopen(), fclose(),
fflush(), and so on; I will need names for those functions, and I
will need to make sure that my names do not conflict with your names.)
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top