473,396 Members | 1,966 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,396 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 4501

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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.