Thread: teaching c/c++ in school

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    630

    teaching c/c++ in school

    Hello

    I'm on computer college and we have recently started with c/c++ programming..

    We had a first hour of c yesterday and since I've been doing c/c++ for about 2-3 years (not so extensively) I have noticed quite some strange things teacher wanted to teach us about..

    We stared with c with hello world program and heres the exact code we had to rewrite:

    Code:
    main() {
    printf("hello world");
    }
    Without even including the libraries for printf on top.. The program didnt want to compile on linux (gcc compiler) and I knew why - thats why I told the teacher what the problem is.. He came to me and started telling me that by default c includes some libraries - blablah - it was obvious he had no idea what he was talking about..

    It amazed me how some people can teach programming language without knowing s___t about it?

    Just had to write this stuff here.. You guys on this board are just great, I have learned so much from you..

    Maybe anyone else got in similar situation?

  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,653
    Yup, if what this individual says is true:
    http://cboard.cprogramming.com/showthread.php?t=99625
    That we've identified another one.
    No real life experiences, however, but maybe I'll find one someday.

    Btw, main should also return int and probably "return 0" at the end.
    Aside from the missing libraries, of course, as you pointed out.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    May 2006
    Posts
    630
    Quote Originally Posted by Elysia View Post
    Yup, if what this individual says is true:
    http://cboard.cprogramming.com/showthread.php?t=99625
    That we've identified another one.
    No real life experiences, however, but maybe I'll find one someday.

    Btw, main should also return int and probably "return 0" at the end.
    Aside from the missing libraries, of course, as you pointed out.
    Yeah, I know that .. Just didnt mention it

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    gcc-mingw 3.4.2 compiles that fine:
    Code:
    D:\temp>echo main() { printf("Hello,World\n"); } > blah.c
    
    D:\temp>gcc blah.c
    
    D:\temp>a.exe
    Hello,World
    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,653
    That's not something to be proud of. That's bad. It should not compile...
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Just to clarify: This is not HOW I WOULD RECOMMEND TO DO THINGS.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,653
    I think you're overreacting, mats
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Elysia View Post
    That's not something to be proud of. That's bad. It should not compile...
    Not proud at all - and if you do "-Wall" which is what I would recommend as settings, it does moan and groan loudly:
    [code
    D:\temp>gcc -Wall -ansi -pedantic blah.c
    blah.c:1: warning: return type defaults to `int'
    blah.c: In function `main':
    blah.c:1: warning: implicit declaration of function `printf'
    blah.c:1: warning: control reaches end of non-void function
    [/code]

    I personally would propose any new code to be developed with "-Werror" - which turns warnings to errors.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,653
    Quote Originally Posted by matsp View Post
    I personally would propose any new code to be developed with "-Werror" - which turns warnings to errors.
    With regards to C, I wholeheartedly agree. Implicit function calls should never have been allowed.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #10
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Elysia View Post
    With regards to C, I wholeheartedly agree. Implicit function calls should never have been allowed.
    I would suggest that "-Wall -Werror" or it's equivalent should also be used in C++.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  11. #11
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,653
    I don't necessarily agree - especially not debug since there are many warnings they can freely be ignored.
    As for release, eliminating warnings is good thing, but again, if you're just compiling a release "for the sake of it" or debugging in release, then it can become a pain, so I usually default it to off.

    But C is an entirely different matter, especially due to the implicit function calls.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #12
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by Elysia View Post
    I don't necessarily agree - especially not debug since there are many warnings they can freely be ignored.
    As for release, eliminating warnings is good thing, but again, if you're just compiling a release "for the sake of it" or debugging in release, then it can become a pain, so I usually default it to off.

    But C is an entirely different matter, especially due to the implicit function calls.
    Implicit function calls is probably not the most useful warning - there are several others that are really helpful [although I can't really think of them right now].

    If you have debug warnings that you need to avoid, why not have something like:
    Code:
    #if DEBUG
    #include "warningsoff.h"
    #endif
    warningsoff.h should contain a selection of individual warnings you want to disable.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  13. #13
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,653
    It's a matter of preference. When I want to kill all warnings (by doing the right thing, not ignoring them), then I do so. But I don't like to be limited to having to fix everything before it compiles, and that's mostly why I don't use it.
    In Visual Studio, you can have different build configs, which is very nice, so I could just put it on in release and off in debug, but again, I found that if I just wanted to compile release for the heck of it or try something, then I have to fix the warnings, so I avoid it.
    One solution might be a "True Release," where I force warnings as errors and remove all debug information to make the app as small as possible-
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  14. #14
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >He came to me and started telling me that by default c includes some libraries - blablah
    Actually, he's right, to a point. C compilers generally link with the standard libraries by default (with a few exceptions, like lm), and resolve the correct function when you use them without declarations. From a practical perspective, the program you were given works on the C implementation that your school is using, and it's likely that other implementations will accept it as well, depending on your settings[1].

    I'm not sure your description of the experience proves that your teacher has no idea what he's talking about. It could be that he's assuming you're a beginner (simplified explanations) and you simply don't agree with his approach to teaching C (starting as simple as possible and moving up[2]).

    [1] For example, if you use -ansi and -pedantic, GCC won't be too happy.
    [2] K&R follows this pattern too. The "hello world" example makes similar errors for the sake of simplicity.
    My best code is written with the delete key.

  15. #15
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    C has a standard, and the standard disallows above program. Teaching a particular implementation of C is just stupid.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. I've been slacking off in high school, am I going to hell
    By Silvercord in forum A Brief History of Cprogramming.com
    Replies: 31
    Last Post: 06-01-2003, 01:00 PM
  2. I Hate My School (rant!!!!)
    By Dalren in forum A Brief History of Cprogramming.com
    Replies: 3
    Last Post: 04-03-2003, 07:10 AM
  3. School Shooting in Germany
    By Golden Bunny in forum A Brief History of Cprogramming.com
    Replies: 27
    Last Post: 04-27-2002, 01:47 PM
  4. Question about going to a technical school
    By Goalie35 in forum C++ Programming
    Replies: 1
    Last Post: 08-30-2001, 11:34 AM