468,484 Members | 1,757 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,484 developers. It's quick & easy.

Function Prototype - different argument names

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

Jul 18 '06 #1
3 3894

cybernerdsx2 wrote:
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
Rgds,

Mike
Jul 18 '06 #2

Mohan wrote:
cybernerdsx2 wrote:
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.
Anyway in the prototype the paramenter names are ignored by the
compiler, it is just required to be a valid identifier.
Rgds,

Mike
Jul 18 '06 #3
In article <11*********************@m79g2000cwm.googlegroups. com>
cybernerdsx2 <fo*********@gmail.comwrote:
>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.hprototypes, 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.)
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (4039.22'N, 11150.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Jul 18 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by kazack | last post: by
3 posts views Thread by domeceo | last post: by
13 posts views Thread by Roy Hills | last post: by
13 posts views Thread by Jim Mackellan | last post: by
9 posts views Thread by Yannick | last post: by
18 posts views Thread by Aaron Gray | last post: by
2 posts views Thread by gieforce | last post: by
reply views Thread by theflame83 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.