Re: [C] One last small problem with that code

From: Arthur J. O'Dwyer (ajo_at_nospam.andrew.cmu.edu)
Date: 08/02/04


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



Relevant Pages

  • Re: Best Asp.net Resources for Newbie
    ... Therefore as a classroom instructor myself and a perpetual student I recommend textbooks to neophytes as one needs to learn a programming language before using the language with the framework to create applications. ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Extra cash in bid to boost Gaelic
    ... I can attest to this in hearing Gaelic as the dominant language spoken ... And as recent as the 1980's Gaelic wasn't taught in Dunblane High School due to an apparent "lack of demand", yet they somehow thought when I was there it made sense to run a Latin class for 4 people and a Russian class for 4 people. ... One of the teachers at Dunblane High taught modern studies but also happened to be a native speaker of Glencoe Gaelic, a Gaelic teacher and a winner of the National Mod Bardic Crown. ...
    (soc.culture.scottish)
  • Re: Help me find 5 mistakes and than solution to thoes mistakes!
    ... > modern operating systems and computers there is just too much for any ... As I have taught a class in programming eons ... > ago, as an instructor, I would give him credit for seeking out this ... > And to Mr. Oberoi, that class I taught, I was a student in until the ...
    (Fedora)
  • Re: Ancient History Question
    ... The point she was making was that conversational French in France is ... way different than the French taught in the US school system. ... the linguist went to Monterey to learn the language. ... My best friend in high school attended the language school in Monterey ...
    (rec.collecting.coins)
  • Re: Perl vs. .NET (was: Re: Programmers (UK)...?)
    ... Being hired to develop in a language and being hired to teach it are ... When I was teaching (and I haven't taught ... I don't mind admitting ignorance. ... Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers ...
    (comp.lang.perl.misc)