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. 20 1468
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.
`main' is not a keyword, and `main' is not a reserved
identifier. It is possible (although perverse) to use `main'
as the name of a macro, or of a variable, or of a struct or
union tag, or ...
#include <stdio.h>
int main(void) {
const char *main = "world";
printf ("Hello, %s!\n", main);
#define main 0
return main;
}
(Not recommended.)
--
Eric Sosman es*****@acm-dot-org.invalid
Eric Sosman <es*****@acm-dot-org.invalidwrit es:
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.
`main' is not a keyword, and `main' is not a reserved
identifier. It is possible (although perverse) to use `main'
as the name of a macro, or of a variable, or of a struct or
union tag, or ...
#include <stdio.h>
int main(void) {
const char *main = "world";
printf ("Hello, %s!\n", main);
#define main 0
return main;
}
(Not recommended.)
And what about calling main as a regular function?
e.g.:
#include <stdio.h>
int main(void)
{
printf("hello") ;
main();
return (0);
}
It makes an infinite recursion with gcc, but i think i've heard that you
can't call main, so is this an undefined behaviour?
--
Simias
email rot13-ified
In article <86************ @simias.hd.free .fr>,
Simias <fv******@tznvy .pbzwrote:
>It makes an infinite recursion with gcc, but i think i've heard that you can't call main, so is this an undefined behaviour?
No, it's perfectly legal to call main().
I can't think of any cases where it wouldn't be clearer to instead
call another function though. main()'s arguments are intended to be
convenient for accessing command line arguments, and that's unlikely
to be a useful internal interface.
-- Richard
--
"Considerat ion shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Simias wrote:
[...]
And what about calling main as a regular function?
e.g.:
#include <stdio.h>
int main(void)
{
printf("hello") ;
main();
return (0);
}
It makes an infinite recursion with gcc, but i think i've heard that you
can't call main, so is this an undefined behaviour?
The sample you show is valid C, but it expresses a program
that does not terminate in any normal fashion. It is likely to
exceed an implementation limit (two limits, actually, but the
problems of generating an infinitely long line of text aren't
immediately relevant to your question) and terminate abnormally.
It is possible to call main recursively, if (as with any
other recursive function) you arrange for the recursion to
"bottom out" eventually. Here is a silly program that prints
its command-line arguments in reverse order:
#include <stdio.h>
int main(int argc, char **argv) {
if (argc 0) {
main (argc-1, argv+1);
puts (*argv);
}
return 0;
}
--
Eric Sosman es*****@acm-dot-org.invalid
small TUX wrote:
Hello programmers;
I joinded today itself.
(UK readers, can you hear Bluebottle saying that as well?)
Can anyone say
about the word main, is it a registered word,
Yes of course someone can and the answer is no it isn't. http://c-faq.com/ansi/avail.html led me to the draft ANSI C89 standard
document which explains that on a "hosted environment" the function
called at program startup is called "main", it returns an int value and
either takes no parameters or 2 parameters (it also defines what these
parameters are).
So "main" is just a function name which has a specific use in hosted
environments. Nothing more, nothing less.
justify your question also.
I don't have a question, so why do I need to justify it? ma**********@po box.com wrote: http://c-faq.com/ansi/avail.html led me to the draft ANSI C89 standard
document which explains that on a "hosted environment" the function
called at program startup is called "main", it returns an int value and
either takes no parameters or 2 parameters (it also defines what these
parameters are).
So "main" is just a function name which has a specific use in hosted
environments. Nothing more, nothing less.
In C99, executing to the closing brace of main is the equivalent of
return 0.
--
Thad
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?
--
Simias
email rot13-ified
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.
--
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.
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
*
|
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,
|
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
|
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...
|
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...
| |
by: junky_fellow |
last post by:
Guys,
Can I return 0, from main() ? Is this equivalent to
exit(EXIT_SUCCESS) ?
thanks for any help...
|
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)
|
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.
|
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);
|
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,...
|
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...
| |
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
|
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();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |