Why C Matters

This is a discussion on Why C Matters within the A Brief History of Cprogramming.com forums, part of the Community Boards category; This is because code that is C++ compliant will also compile under C, excluding classes. Excluding a lot of other ...

  1. #31
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    This is because code that is C++ compliant will also compile under C, excluding classes.
    Excluding a lot of other things... These are 2 different languages

    Where do you have new/delete in C?
    Or function overloading?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  2. #32
    l'Anziano DavidP's Avatar
    Join Date
    Aug 2001
    Location
    Plano, Texas, United States
    Posts
    2,738
    This is because code that is C++ compliant will also compile under C, excluding classes. Code that compiles under C may not necessarily compile as C++.
    Actually it is quite the other way around. For the most part, any C program will compile successfully with a C++ compiler...but there is no possible way for a C compiler to compile a pure C++ program.

    This is growing less true, however. Although I have not tested any specific cases myself, I have heard lately that C++ has begun to diverge enough from C that not all C code is compilable in C++ compilers anymore.
    My Website

    "Circular logic is good because it is."

  3. #33
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    Quote Originally Posted by abachler View Post
    This is because code that is C++ compliant will also compile under C, excluding classes.
    Here's a list of why that is wrong...

    # anonymous unions
    # classes
    # constructors and destructors
    # exceptions and try/catch blocks
    # external function linkages (e.g., extern "C")
    # function overloading
    # member functions
    # namespaces
    # new and delete operators and functions
    # operator overloading
    # reference types
    # standard template library (STL)
    # template classes
    # template functions
    # // comments
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

  4. #34
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,851
    > I have heard lately that C++ has begun to diverge enough from C that not all C code
    > is compilable in C++ compilers anymore.
    It was never true from the beginning, never mind now.

    All those extra keywords added by C++, like class. They're perfectly valid C identifiers. So right from the beginning
    int class;
    would cause a C++ compiler to barf.

    http://david.tribble.com/text/cdiffs.htm
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #35
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    Quote Originally Posted by Salem View Post
    What there seems to be a lack of is people being taught how to program. Sure there's lots of focus on teaching programming languages, but that's only half the story. Producing a working program is a lot more effort than simply pressing the keys in the right order.

    But it seems that's all a lot of courses seem to require, because it's very easy to verify. Either you get the expected output or you don't. Assessing code quality, thoroughness of design etc etc is nowhere. If it were, perhaps we'd see less code posted here that looks like it was a dogs chew toy.

    A fair proportion of very large programs require more than one language to begin with. Again, this comes from an engineering perspective and treating languages as nothing more than tools which are specialised in solving particular kinds of problems.

    It's the car analogy I keep posting. There's way too many people rushing about who don't have a clue how to drive.
    15 years ago, when I was in college, there were people already in there that were saying
    Quote Originally Posted by Idiot CS Students
    Computer Science wouldn't be so bad if there wasn't all that programming!
    (Please note that I know the difference between an idiot CS Student and a good CS Student).

    I want to second Salem on this one. A "real" programmer would be one that 1) knows HOW to program, 2) knows HOW to learn a language, 3) knows HOW things work BEFORE he/she begins to work on the project, and 4) is not afraid to attempt to solve a problem in some other language -- even if he/she does not know that language.

    It would seem that we are getting too far removed from the KISS model of programming. When one uses something like VB/Java to do hardware programming, one can expect problems to occur later.

    My 0.02 USD.

  6. #36
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    Quote Originally Posted by vart View Post
    Excluding a lot of other things... These are 2 different languages

    Where do you have new/delete in C?
    Or function overloading?
    since new/delete is primarily for creating/destroying classes new instantiations of classes, this woudl fall under classes. otherwise you can just use malloc/free which have the exact same effect when applied to things other than classes. Cry about malloc/free not being part of C, but they are in EVERY standard library out there. I know of no working implementation that does not include them, although im sure someone will find some little known example to try to 'prove' me wrong.

    As for function overloading, its called function renaming, The C++ preprocessor just handles it automatically for you. So again, other than classes, there arent any intrinsic differences between C and C++. You can take a C compiler and easily add those features that woudl mke it a C++ compiler. Not so with a different language like Java or VB or COBOL, Fortran, Ada, ML etc. Try upgrading Clipper to C++ and you will understand what a different language means. Going from C to C++ is trivial.
    Last edited by abachler; 01-09-2008 at 04:24 PM.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  7. #37
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,762
    >Cry about malloc/free not being part of C, but they are in EVERY standard library out there.

    Well, the only problem with that statement is that malloc and free are Standard functions. Sure, people will reimplement the Standard from time to time (dmalloc) to add something, but that statement is just wrong. For all intents and purposes it is a part of C.

  8. #38
    Dr Dipshi++ mike_g's Avatar
    Join Date
    Oct 2006
    Location
    On me hyperplane
    Posts
    1,218
    You can take a C compiler and easily add those features that woudl mke it a C++ compiler.
    Wow, can you? I cant C++ has quite a lot of useful features. Templates rule!

  9. #39
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    Quote Originally Posted by abachler View Post
    As for function overloading, its called function renaming, The C++ preprocessor just handles it automatically for you.
    You're right, function overloading is usually implemented by "mangling" the names of the functions to include some information about the function's arguments. However, it's the compiler that does this, not the preprocessor. The preprocessor does very few things, among them:
    • File inclusion with #include.
    • Conditional compilation with #if etc.
    • Macros with #define.
    • Comments (the preprocessor strips them).
    • String literal concatenation.


    The first C++ "compiler" was actually a source-to-source translator: it simply converted C++ into C. So every feature of C++ can be represented in C. In fact, every feature of C++ can be represented in assembly -- that's how compilers can exist.

    But that doesn't mean we should be programming directly in assembly just because C++ can be converted into assembly. It's convenience, and abstraction, that makes us use higher-level languages.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  10. #40
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    since new/delete is primarily for creating/destroying classes
    it is for dynamic memory allocation, what it has to do with classes? If you do not use classes?

    Code:
    int* arr = new int[15];
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  11. #41
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    I dont disagree with you dwks, but I dont see C++ as a seperate language from C. It has more features for sure, just as modern english is more descriptive than english of say 100 years ago. Both can be translated into grunts whistles and other basic phoenetic primitives. That doesnt make 19th century english and modern english 2 seperate languages, nor does it mean we should all go around speaking in phoenetics either. I can obviously translate any modern phrases into terms in use in the 19th century, granted it woudl take longer to express teh same concepts, just as it woudl take more lines of code to express the same behavior in C as in C++. Again, this does not make them seperate languages, merely differnt dialects at most.

    Quote Originally Posted by vart View Post
    it is for dynamic memory allocation, what it has to do with classes? If you do not use classes?
    new/delete is the primary way to instantiate a class. it is a bit difficult to instantiate a class using malloc. I really fail to see what you are asking?

    Code:
    int* arr = new int[15];
    can be just as easily expressed in C as

    Code:
    int* arr = malloc(15 * sizeof(int));
    Last edited by abachler; 01-09-2008 at 11:10 PM.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  12. #42
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    can be just as easily expressed in C as
    That's the idea - use C when you need C, do not use C++ because you anyway will need to rewrite the code to compile it as C
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  13. #43
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    C and C++ are considerably less similar than C# and Java. Does that make Java and C# "merely dialects" of the same language?
    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

  14. #44
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,303
    heheh, geneticists argue that tracing common ancestry based on morphological features is less reliable than using DNA. Borrowing their point of view, can C++, C# and Java trace their ancestry from C (and so are part of one C family), or is only C++ a direct descendant from C and thus a dialect of C, whereas C# and Java are entirely different languages?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  15. #45
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    Well, both C# and Java can directly trace their ancestry to C++. In the family of programming languages, C# and Java are siblings, children of C++ and Smalltalk, really. C++ is a child of mostly C and Simula.
    The main difference is that C++ was developed with C source and binary compatibility in mind, whereas C# and Java had no such ambitions, neither with C++ nor with each other.
    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. Speed of C++
    By bobthebullet990 in forum A Brief History of Cprogramming.com
    Replies: 64
    Last Post: 01-12-2007, 02:39 AM
  2. Replies: 2
    Last Post: 09-28-2006, 02:06 PM
  3. C++ tests.
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 38
    Last Post: 06-30-2006, 07:51 AM
  4. Confuted/Blackrat: quaternion question
    By Silvercord in forum Game Programming
    Replies: 12
    Last Post: 08-18-2003, 07:02 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21