Re: [C] One last small problem with that code
From: Arthur J. O'Dwyer (ajo_at_nospam.andrew.cmu.edu)
Date: 08/02/04
- Next message: Rusty Shackleford: "Contest: Overly complicated Hello.cpp"
- Previous message: Paul Fedorenko: "Re: [C] One last small problem with that code"
- In reply to: Paul Fedorenko: "Re: [C] One last small problem with that code"
- Next in thread: Francis Glassborow: "Re: [C] One last small problem with that code"
- Reply: Francis Glassborow: "Re: [C] One last small problem with that code"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sun, 1 Aug 2004 21:28:16 -0400 (EDT)
On Sun, 1 Aug 2004, Paul Fedorenko wrote:
>
> On Sun, 1 Aug 2004 22:36:45 +0100, Francis Glassborow wrote:
>[Someone else --- Paul? --- wrote:]
>>> void main() is what we're being taught in the class, so that's what I
>>> used by default. I guess I could use int main() instead, but I'd have
>>> tor emember to put "return 0" at the end of the program, wouldn't I?
>>> Otherwise I'd get an error of some sort...
>>
>> Sad to say, if that is what you are being taught then the instructor
>> does not know C++ as well as s/he should. That leaves me wondering what
>> else the instructor does not know.
>
> He's teaching us to use void main().
Then he is not teaching you correctly. Do not follow his rules in
this case. If you feel up to it, consider pointing out his error;
he'll thank you next year. :)
> I'm the one who assumed,
> apparently erroneously, that if I used int main() I'd have to include
> return 0 at the end of the main() function.
An explicit 'return 0;' from 'main' is basically required in C90 (the
C language that's likely to be taught in schools). It is not required in
the latest C standard language, nor (according to Francis, whom I believe)
in C++. That is,
int main(void)
{
}
is a perfectly conforming C99 and C++ program.
void main()
{
}
has never been correct, and will never be correct, in either language.
> I don't think the
> instructor's ever made mention of using the return command with the
> main() function specifically.
'return' is technically a /statement/; C++ doesn't have /commands/.
(Terminology is important sometimes, so IMHO it's good to get in the
habit of using the correct terminology even when, as here, it's obvious
what you mean.)
'return' from 'main' is just like 'return' from any other function,
except that once you return from the very "top level" of the program,
the program ends. Nothing terribly surprising happens. ;)
[re: isolating system-specific functions]
>> void clear_screen();
>
> Makes sense. I'll keep that in mind when I start writing my own
> header files.
Good idea. But note that in this case, pretty much every experienced
computer user you'll meet will tell you that clearing the user's screen
is an awful idea. You have no idea what was on the screen to begin with,
so what right do you have to start arbitrarily erasing it? All decent
OSes :) have a built-in command or program like 'clear' or 'cls'
accessible to the user; let /him/ decide whether to use it, and just let
your programs get on with the adding up.
-Arthur,
thank you very much
- Next message: Rusty Shackleford: "Contest: Overly complicated Hello.cpp"
- Previous message: Paul Fedorenko: "Re: [C] One last small problem with that code"
- In reply to: Paul Fedorenko: "Re: [C] One last small problem with that code"
- Next in thread: Francis Glassborow: "Re: [C] One last small problem with that code"
- Reply: Francis Glassborow: "Re: [C] One last small problem with that code"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|