W
Wang Yip
Hello I read Main shall not return Void but I always use and always
work.... who is right
work.... who is right
Hello I read Main shall not return Void but I always use and always
work.... who is right
Many compilers have options to turn off standards checking (or skip itsuperpollo said:Wang Yip ha scritto:
maybe some compilers are more forgiving than others ?
The function named Main() can return anything you like.
Anything, or nothing. No restrictions: Do what you will,
even to the extent of returning a value of type Void (which
you can #define or typedef as you please).
In a hosted implementation, the function named main()
and having external linkage must be defined as returning an
int value, and must actually return one if it returns at all.
Under C99 rules, "falling off the end" of this function returns
the int value zero; under earlier versions of the Standard the
return had to be explicit.
... and this topic has been BEATEN TO DEATH so many times
that I cannot imagine anyone wanting to go through it yet again.
Eric Sosman said:The function named Main() can return anything you like.
Anything, or nothing. No restrictions: Do what you will,
even to the extent of returning a value of type Void (which
you can #define or typedef as you please).
In a hosted implementation, the function named main()
and having external linkage must be defined as returning an
int value, and must actually return one if it returns at all.
Under C99 rules, "falling off the end" of this function returns
the int value zero; under earlier versions of the Standard the
return had to be explicit.
Hello I read Main shall not return Void but I always use and always
work.... who is right
Keith said:In case you misseed it, Eric's point is that C is case-sensitive;
"Main" and "main" are two distinct and unrelated identifiers.
And if you incorrectly declare main as "void main(void)", your
program's behavior is undefined. It's an error that your compiler
isn't required to diagnose. So if your compiler quietly accepts it
and your program appears to work, that doesn't mean either that you
got it right or that your compiler got it wrong. It's entirely *your*
responsibility to get this right.
Johannes Schaub (litb) said:Keith Thompson wrote: [...]And if you incorrectly declare main as "void main(void)", your
program's behavior is undefined. It's an error that your compiler
isn't required to diagnose. So if your compiler quietly accepts it
and your program appears to work, that doesn't mean either that you
got it right or that your compiler got it wrong. It's entirely *your*
responsibility to get this right.
I was in the impression that the C99 Standard allows implementations to
provide additional return types. If an implementation supports "void", then
behavior is not undefined. This is what i infer out of the "It shall be
defined with return type of int ... or in some other implementation-defined
manner."
If, however, the implementation does not allow it, behavior is undefined. Is
my interpretation wrong?
Johannes Schaub (litb) said:Keith Thompson wrote:
[...]
And if you incorrectly declare main as "void main(void)", your
program's behavior is undefined. It's an error that your compiler
isn't required to diagnose. So if your compiler quietly accepts it
and your program appears to work, that doesn't mean either that you
got it right or that your compiler got it wrong. It's entirely *your*
responsibility to get this right.
I was in the impression that the C99 Standard allows implementations to
provide additional return types. If an implementation supports "void", then
behavior is not undefined. This is what i infer out of the "It shall be
defined with return type of int ... or in some other implementation-defined
manner."
If, however, the implementation does not allow it, behavior is undefined. Is
my interpretation wrong?
You're right. I left that out in the vain hope of avoiding yet
another lengthy discussion.
Yes, an implementation may permit other declarations for main,
including "void main(void)". If a given implementation permits that
declaration (and documents it), then such a program's behavior is
well defined *for that implementation*.
There is no good reason for an implementation to permit "void
main(void)", and no good reason for a programmer to take advantage
of it. "int main(void)" works everywhere.
One quibble: on freestanding implementations (roughly speaking,
embedded systems), "void main(void)" might be perfectly sensible.
But most beginners don't use such implementations.
[...]Wang Yip said:Hi What is the Void in parenthesis. I am familiar
Main() {...}
and
Void Main() {...}
but what is the
Void Main(Void)
mean. How to pass one Void argument. Do you intend Void Main(Void *)....
I find C very confused........
Wang Yip said:Hi What is the Void in parenthesis. I am familiar
Main() {...}
and
Void Main() {...}
but what is the
Void Main(Void)
mean. How to pass one Void argument. Do you intend Void Main(Void *)....
I find C very confused........
[...]
Please don't top-post. See:
http://www.caliburn.nl/topposting.html
http://www.cpax.org.uk/prg/writings/topposting.php
C is case-sensitive. "Main" and "main" are two distinct identifiers,
as are "Void" and "void".
In a function declaration, the "(void)" syntax means that the
function has no parameters. It would have made more sense to use
"()" for this, but for historical reasons this special-case syntax
was necessary (empty parentheses already had a different meaning).
This is a very elementary question. We're here to help (well,
most of us are), but you're not going to have much luck learning
the language by asking one question at a time. I think you'll be
more successful if you use a good book. I recommend Kernighan &
Ritchie's "The C Programming Language", 2nd edition, affectionately
known as K&R2. There are also some good online tutorials (and a
whole lot of really bad ones).
See questions 18.9 and 18.10 of the comp.lang.c FAQ,
<http://www.c-faq.com/>, and follow the links. (The FAQ is an
excellent resource, but not suitable for learning the language
from scratch.)
Wang Yip said:Hi yet I not understand... How to pass a Void argument.
[...]In the code I use small letters but I find clearer to write with big
letters Void to show is C type not word. I can not afford book... pls
send a rapidshare link for "The C Programming Language" thanks......
program there is error.Wang Yip said:Hi yet I not understand... How to pass a Void argument.
There is no such thing as a void argument. As I explained, in
"int main(void)" the "(void)" is a special-case syntax that means
that the function takes no arguments.
In the code I use small letters but I find clearer to write with big
letters Void to show is C type not word. I can not afford book... pls
send a rapidshare link for "The C Programming Language" thanks......
[...]
Again, please don't top-post. Your response belongs *below* any
quoted text, not above it. Please read the following links before
posting again:
http://www.caliburn.nl/topposting.html
http://www.cpax.org.uk/prg/writings/topposting.php
Capitalizing words such as "void" and "main" that are inherently
lowercase is not helpful, and will only cause confusion. If you
want to make it clear that you're referring to a C keyword or
identifier rather than an English word, find some other way to
do it; quotation marks are usually a reasonable way to do this.
In this context, though, even that probably isn't necessary; it's
clear enough from context what void and main mean.
I already cited questions 18.9 and 18.10 of the comp.lang.c FAQ,
<http://www.c-faq.com/>. If you had read them, you would have
found several online tutorials. I don't know what "rapidshare" is,
but as far as I know there are no *legitimate* copies of K&R2 other
than printed ones, and I won't help you obtain an illegitimate copy.
Hi Thanks to your great help.... I understand now but when I try below
I was in the impression that the C99 Standard allows implementations to
provide additional return types.
If an implementation supports "void", then
behavior is not undefined. This is what i infer out of the "It shall be
defined with return type of int ... or in some other implementation-defined
manner."
If, however, the implementation does not allow it, behavior is undefined. Is
my interpretation wrong?
Hi What is the Void in parenthesis.
I find C very confused........
Hi yet I not understand... How to pass a Void argument.
In the code I use small letters but I find clearer to write with big
letters Void to show is C type not word.
I can not afford book... pls
send a rapidshare link for "The C Programming Language" thanks......
Hi Thanks to your great help.... I understand now but when I try below
program there is error.
#define V (void)x
Wrong.
f(void)
{
printf("calling f.........................\n");
}
main()
{
int x;
f(V);
}
I also try with int main(void)..... But then if I give a command line
parameter there is no error but I understand you say (void) is NO arguments.
Rapidshare is free download site... look for it, many good warez.
Keith Thompson said:C is case-sensitive. "Main" and "main" are two distinct identifiers,
as are "Void" and "void".
f(){...}Then you don't understand now.
The correct call would be:
f();
Right. (void) means no function arguments, it doesn't say anything about
what the calling enviroment might have done.
I'd like to walk you through this slowly.
You are writing to programmers. Do you know what programmers do for a
living, in general? They write programs. Many of these programs are
sold. If the program does not sell, there is no job for the programmer.
Some of us write books. If the book does not sell, there is no job for
the writer. (I'm glossing over internal-use-only code, of which there is
a fair bit, because it's a bit of a special case.)
In short, you're coming to a group of people most of whom make money selling
books or programs, and telling them that you are a big fan of downloading
things without paying the creators for them. Now, can you imagine any way
in which this could make people less likely to help you? I sure can.
-s For call f(); I will just write
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.