Thread: is C appropriate for intro to computers?

  1. #46
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    It was put in C89 for compatibility with legacy code. It's not in C99, as Mario said. If you don't want it in C89, then disallow it with a compiler switch, or use a static code checker, or both.

  2. #47
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Yeah, I get it was there for a purpose, but that doesn't mean I agree with it.
    BUT it is good to know that it isn't there in C99. C99 actually seems to fix a number of small issues, mainly implicit function types and the whole ordeal with calling functions without prototypes.
    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. #48
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Are you adverse to using a compiler switch to fix that problem in C89?

  4. #49
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    I just don't see why you always rag on C, Elysia. I mean I do realize that I do write a lot of C++ code and all, and perhaps I am just fond of C because it was what some of my proudest projects were written in. But either way I don't see what difference it makes. At least I don't like C#. Everytime someone says they like C# a sun microsystems angel loses its wings.

  5. #50
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Quote Originally Posted by robwhit View Post
    Why would it?
    What's your point exactly?
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  6. #51
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Quote Originally Posted by Elysia View Post
    mainly implicit function types and the whole ordeal with calling functions without prototypes.
    Note that those are the same thing.
    Quote Originally Posted by Mario F. View Post
    What's your point exactly?
    That that code is legal and that it shouldn't trigger a warning like you implied.

  7. #52
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Quote Originally Posted by robwhit View Post
    Note that those are the same thing.That that code is legal and that it shouldn't trigger a warning like you implied.
    Actually I didn't try to imply it would. I did say however it was undefined, which it is. The point was exactly that undefined behavior shouldn't necessarily trigger warnings.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  8. #53
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    I don't see how it's undefined.

  9. #54
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Err... the compiler is free to choose which side of the assignment it evaluates first, rob.

    EDIT:

    Quote Originally Posted by C++ Standard ISO-IEC 14882-2003(E) - 5 Expressions, &#167 View Post
    Except where noted, the order of evaluation of operands of individual operators and subexpressions of individual
    expressions, and the order in which side effects take place, is unspecified.53) Between the previous
    and next sequence point a scalar object shall have its stored value modified at most once by the evaluation
    of an expression. Furthermore, the prior value shall be accessed only to determine the value to be stored.
    The requirements of this paragraph shall be met for each allowable ordering of the subexpressions of a full
    expression; otherwise the behavior is undefined. [Example:
    i = v[i++]; // the behavior is unspecified
    i = 7, i++, i++; // i becomes 9
    i = ++i + 1; // the behavior is unspecified
    i = i + 1; // the value of i is incremented
    —end example]
    Last edited by Mario F.; 10-06-2008 at 03:37 PM.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  10. #55
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Ah yes I was confused. I thought the post-increment operator would only take effect after the sequence point was encountered, but I was confusing things.
    Last edited by robwhit; 10-06-2008 at 03:38 PM.

  11. #56
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    It took me a while to see the undefined behavior also.
    Code:
    bar[i] = foo[i++];

  12. #57
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    Could you perhaps explain it to me then? Because neither example attempts to modify i more than once. That would be the only place undefined behavior could occur.

    bar[i] = foo[i++];
    i++ evaluates to i for both sides, bar[i] is assigned, and after the sequence point is encountered, the increment occurs. Am I wrong? i = v[i++]; seems to be the closest thing that would support Mario's claim but that isn't happening here.

    And see http://www.difranco.net/cop2220/op-prec.htm, or perhaps any other table for information on delayed increments. There's likely chapter and verse somewhere...

  13. #58
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    I thought that too, but I think the relevant part is here:
    Furthermore, the prior value shall be accessed only to determine the value to be stored.

  14. #59
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,613
    Ah, well, err to the side of caution I suppose.

  15. #60
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    My apologies.
    I tried to display that undefined behavior behind an implementation only to further the idea C++ (whether through its C roots or not is irrelevant) also has its share of undefined behavior and no compiler warnings, as seems to be Elysia's major gripe with C and her crusade to rid the world of C textbooks.

    Perhaps I overdid it. So apologies again.
    But I feel It could go much further. It is often said of C++ that with C you are given a gun with which you can accidentally shoot your own foot, but with C++ you can blow your whole leg off (or some variation of this). If we were to crusade against languages for their inherent general-purpose idiosyncrasies, there would not be any programming languages in the world and not even interpreted languages would have a chance at being developed.
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Numeric addresses for computers
    By great in forum C Programming
    Replies: 4
    Last Post: 08-23-2010, 11:53 AM
  2. Computers as authors
    By hk_mp5kpdw in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 11-22-2004, 08:55 PM
  3. Industrial vs home computers
    By nbo10 in forum Tech Board
    Replies: 10
    Last Post: 09-01-2004, 02:04 AM
  4. Matrix and vector operations on computers
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 05-11-2004, 06:36 AM
  5. Love programming, hate computers
    By PJYelton in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 12-14-2002, 01:04 PM