473,805 Members | 2,008 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Is main a registered word

Hello programmers;
I joinded today itself. Can anyone say
about the word main, is it a registered word, justify your question
also. I would like to point about one thing that we can make variables
with name main.
Thanks.

Dec 8 '06
20 1471
In article <11************ **********@n67g 2000cwd.googleg roups.com>,
santosh <sa*********@gm ail.comwrote:
> If the return type of the main function is a type compatible with
int, a return from the initial call to the main function is
equivalent to calling the exit function with the value returned by
the main function as its argument; reaching the } that terminates
the main function returns a value of 0.

The way it's phrased, I think the last clause refers to any call to
main, not just the initial call.
>It seems to contradict the preceding statement. Anyhow, what if the
code returns a value other than zero, say EXIT_FAILURE?
Then it doesn't reach the }.
>I suppose the last statement is meant for the situation where main() is
prototyped as returning an int value, but the code itself fails to
return an explicit value, terminating by just a return.
It's meant for the case where it doesn't reach a return statement at
all, but reaches the } at the end of the function. On the other hand
this presumably does something undefined:

int main(void)
{
return;
}

-- Richard
--
"Considerat ion shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Dec 8 '06 #11
Keith Thompson wrote:
Simias <fv******@tznvy .pbzwrites:
Thad Smith <Th*******@acm. orgwrites:
ma**********@po box.com wrote:
In C99, executing to the closing brace of main is the equivalent of
return 0.
Even if it's a recursive call to main?

I think so.

C99 5.1.2.2.3 says:

If the return type of the main function is a type compatible with
int, a return from the initial call to the main function is
equivalent to calling the exit function with the value returned by
the main function as its argument; reaching the } that terminates
the main function returns a value of 0.

The way it's phrased, I think the last clause refers to any call to
main, not just the initial call.
On the other hand, the way it's phrased (without the word "and" before
"reaching") , it also seems to refer to any call to main() regardless of
the return type. That is, if an implementation documents void(void) as
one of the implementation-defined allowed types for main(), the
standard seems to state

void main(void) {
}

is equivalent to

void main(void) {
return 0;
}

which then of course requires a diagnostic. I doubt this is intended;
it makes far more sense for the last clause to refer to less than
suggested by the current wording. How much less is anyone's guess.

Dec 8 '06 #12
2006-12-08 <11************ **********@n67g 2000cwd.googleg roups.com>,
santosh wrote:
Keith Thompson wrote:
>Simias <fv******@tznvy .pbzwrites:
Thad Smith <Th*******@acm. orgwrites:
ma**********@po box.com wrote:
In C99, executing to the closing brace of main is the equivalent of
return 0.

Even if it's a recursive call to main?

I think so.

C99 5.1.2.2.3 says:

If the return type of the main function is a type compatible with
int, a return from the initial call to the main function is
equivalent to calling the exit function with the value returned by
the main function as its argument; reaching the } that terminates
the main function returns a value of 0.

The way it's phrased, I think the last clause refers to any call to
main, not just the initial call.

It seems to contradict the preceding statement. Anyhow, what if the
code returns a value other than zero, say EXIT_FAILURE?
Execution paths that reach a return statement will not reach the } that
terminates the function.
Dec 8 '06 #13

small TUX wrote:
Hello programmers;
I joinded today itself. Can anyone say
about the word main, is it a registered word, justify your question
also. I would like to point about one thing that we can make variables
with name main.
Thanks.
It is possible (in some implementations ) to get yourself into trouble
with this program:

C:\tmp>type foo.c
int main;

Or even this:
C:\tmp>type bar.c
main;

because it will create a public variable with signature
_main

Though most modern implementations won't try to execute a constant and
dump core.

Dec 8 '06 #14
Simias wrote:
Eric Sosman <es*****@acm-dot-org.invalidwrit es:

`main' is not a keyword, and `main' is not a reserved
identifier. ...

And what about calling main as a regular function?
Allowed in C.
... i think i've heard that you can't call main, so is this an
undefined behaviour?
It's not allowed in C++.

--
Peter

Dec 8 '06 #15
"santosh" <sa*********@gm ail.comwrites:
Keith Thompson wrote:
>Simias <fv******@tznvy .pbzwrites:
Thad Smith <Th*******@acm. orgwrites:
ma**********@po box.com wrote:
In C99, executing to the closing brace of main is the equivalent of
return 0.

Even if it's a recursive call to main?

I think so.

C99 5.1.2.2.3 says:

If the return type of the main function is a type compatible with
int, a return from the initial call to the main function is
equivalent to calling the exit function with the value returned by
the main function as its argument; reaching the } that terminates
the main function returns a value of 0.

The way it's phrased, I think the last clause refers to any call to
main, not just the initial call.

It seems to contradict the preceding statement. Anyhow, what if the
code returns a value other than zero, say EXIT_FAILURE?

I suppose the last statement is meant for the situation where main() is
prototyped as returning an int value, but the code itself fails to
return an explicit value, terminating by just a return.
The first clause, before the ';', says that returning a value from
main() is equivalent to calling exit() with that same value. This
applies only to the initial call, and only if main's return type is
compatible with int.

The second call, after the ';', says that reaching the '}' at the end
of main() is equivalent to returning a value of 0.

I don't see a contradiction, but I do seem an ambiguity. As Harald
pointed out, there are two conditions stated in the first clause: that
the return type is compatible with int, and that the call is the
initial call. The first condition (return type compatible with int)
logically *should* apply to the second clause (falling off the end
returns 0). The second condition (initial call) logically may or may
not. The way the sentence is structured, I don't think that *either*
condition applies to the second clause -- but if that were the intent,
it would have made more sense to write two sentences rather than using
a semicolon.

It doesn't matter much to me as a programmer; I have no intention of
taking advantage of the ability to fall off the end of main() without
an explicit exit() or return statement. And an implementer can meet
the requirements, whatever they may be, by always returning 0 when a
program reaches the closing "}" of main(), whether it's the initial
call or not (that's probably the easiest thing to do anyway). But it
would be nice to know exactly what's intended.

I'll post to comp.std.c.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Dec 8 '06 #16
dc*****@connx.c om writes:
small TUX wrote:
>Hello programmers;
I joinded today itself. Can anyone say
about the word main, is it a registered word, justify your question
also. I would like to point about one thing that we can make variables
with name main.
Thanks.

It is possible (in some implementations ) to get yourself into trouble
with this program:

C:\tmp>type foo.c
int main;

Or even this:
C:\tmp>type bar.c
main;

because it will create a public variable with signature
_main

Though most modern implementations won't try to execute a constant and
dump core.
The grand prize winner of the first IOCCC (International Obfuscated C
Code Contest), back in 1984, declared "main" as an array rather than
as a function. (The content of the array was machine code that could
be executed either on a PDP-11 or on a VAX.) The implementations of
the time happily executed the array. It resulted in a rule change for
the following year.

<http://www0.us.ioccc.o rg/years.html#1984 >, "mullender" .

Here's the actual program (I accept no responsibility for the
consequences if you try to run it):

short main[] = {
277, 04735, -4129, 25, 0, 477, 1019, 0xbef, 0, 12800,
-113, 21119, 0x52d7, -1006, -7151, 0, 0x4bc, 020004,
14880, 10541, 2056, 04010, 4548, 3044, -6716, 0x9,
4407, 6, 5568, 1, -30460, 0, 0x9, 5570, 512, -30419,
0x7e82, 0760, 6, 0, 4, 02400, 15, 0, 4, 1280, 4, 0,
4, 0, 0, 0, 0x8, 0, 4, 0, ',', 0, 12, 0, 4, 0, '#',
0, 020, 0, 4, 0, 30, 0, 026, 0, 0x6176, 120, 25712,
'p', 072163, 'r', 29303, 29801, 'e'
};

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Dec 8 '06 #17
"santosh" <sa*********@gm ail.comwrites:
[...]
I suppose the last statement is meant for the situation where main() is
prototyped as returning an int value, but the code itself fails to
return an explicit value, terminating by just a return.
I forgot to mention: A return statement without an expression in a
non-void function, or a return statement with an expression in a void
function, is a constraint violation. (That's in C99; I think the
rules were looser in C90.)

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Dec 8 '06 #18
In article <ln************ @nuthaus.mib.or gKeith Thompson <ks***@mib.orgw rites:
"santosh" <sa*********@gm ail.comwrites:
[...]
I suppose the last statement is meant for the situation where main() is
prototyped as returning an int value, but the code itself fails to
return an explicit value, terminating by just a return.

I forgot to mention: A return statement without an expression in a
non-void function, or a return statement with an expression in a void
function, is a constraint violation. (That's in C99; I think the
rules were looser in C90.)
Indeed, C90 allows a return without value in a non-void function.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Dec 8 '06 #19
On 8 Dec 2006 05:15:41 -0800, in comp.lang.c , "small TUX"
<pa*********@ya hoo.comwrote:
I joinded today itself. Can anyone say
about the word main, is it a registered word, justify your question
you mean justify the answer.
this sounds like homework. You probably need to do that yourself.
--
Mark McIntyre

"Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it."
--Brian Kernighan
Dec 9 '06 #20

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
2212
by: Steven T. Hatton | last post by:
The short sample program listed below has some features that I find to be bad style. In particular, they fail to communicate the connection between names used in this program and the location in which they are declared and or defined. I'd like to know if there are any features of this code you believe represents bad programming technique. How would the feature be better implemented? /* * The Apache Software License, Version 1.1 *
2
2958
by: anand | last post by:
Hi, We have developed a web application, which uses Interop.Word.dll to read from word documents and write to word documents. Problem is that our client is persisting that we develop the solution in such a way that the app can be deployed in a machine where Office is not installed! I read that Word dlls are not redistributables. We tried to create a Setup (Installer), include the dll dependencies Interop.Word.dll,
3
4885
by: Hughsie | last post by:
Hi I have created an installation package for my app and I have installed the application onto another machine together with the framework and the correct MDAC version. The problem is when I access something in the application that uses one of the required dlls. All the dlls have been included with the application in the same
0
6257
by: ritesh.singhal | last post by:
Hi, I am trying to do server side office automation. I have a word template which I am trying to populate with data from SQL server but when I try to generate the Word document I get following error: Unable to cast COM object of type 'Word.ApplicationClass' to interface type 'Word._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID...
2
3380
by: Colin Halliday | last post by:
I have a Word 2003 mail merge main document (form letter) that is linked to another Word document data source for the mail merge. If I open this doc using the Word GUI, it first asks me to confirm that I want to run a query to select the data from the data source file, then it opens the form letter fine. I can preview the merged records and complete a merge to a new document. I have a VB 2006 project (.net framework 2.0) which opens the...
27
2510
by: junky_fellow | last post by:
Guys, Can I return 0, from main() ? Is this equivalent to exit(EXIT_SUCCESS) ? thanks for any help...
2
11887
by: significantBit | last post by:
n00b here. Just started learning C a couple of days ago. I'm using xcode alternatively with emacs. My question is in regards to the main function. Everytime I create a project (standard command utility) with xcode, my main function starts out looking like this: int main(int argc, const char * argv)
17
2049
by: mariz | last post by:
hi , i m a new member to this group . i start from the beginig - main(). Can any one give me an idea for how to write a program in C without using main() ? ie while looking source code it wont contain main keyword.
11
2851
by: Rahul | last post by:
Hi Everyone, I have seen code in different styles like main(argc,argv) int argc; char **argv; { if(argc != 2) exit(1); else exit(0);
0
9718
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10613
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10368
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10107
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7649
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6876
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4327
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3846
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.