473,327 Members | 2,118 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

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 4494

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 (40°39.22'N, 111°50.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: kazack | last post by:
I am a little confused with code I am looking at. My c++ book does not go into passing a structure to a function so I pulled out a c book which does. and I do not understand the prototype verses...
3
by: domeceo | last post by:
can anyone tell me why I cannot pass values in a setTimeout function whenever I use this function it says "menu is undefined" after th alert. function imgOff(menu, num) { if (document.images) {...
6
by: marktm | last post by:
Hi- I am trying to use setInterval to call a method within an object and have not had any luck. I get "Object doesn't support this property or method" when I execute the following code. What I...
13
by: Roy Hills | last post by:
I've seen two different function prototype formats used for ANSI C, and I'm unsure as to which is the correct or preferred one. 1st Format (this is what I use) type function(type, type, type);...
28
by: Larax | last post by:
Best explanation of my question will be an example, look below at this simple function: function SetEventHandler(element) { // some operations on element element.onclick = function(event) {
28
by: ravi | last post by:
Hello everybody, I am writing a small application which does some work before the user main function starts execution. I am trying to #define the main function. But the problem is that,
13
by: Jim Mackellan | last post by:
In my opinion, C not mungling its function names imposes unnecessary complexity on C++, requiring extern 'C' { ... } everywhere in headers. I believe that in the next version of the ISO standard,...
9
by: Yannick | last post by:
Hi everyone - I am not quite sure to understand what is really going on when a function defined in one translation unit calls a function defined in a different translation unit without knowing...
18
by: Aaron Gray | last post by:
I know this has probably been argued to death, but I am going to raise it fresh again, and basically lets have an unofficial 'isArray()' contest that we can hopefully put it to rest as best as we...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.