Definite Answer Needed

This is a discussion on Definite Answer Needed within the C Programming forums, part of the General Programming Boards category; Would somebody please, PLEASE, tell me plain and simple: Can C code be compiled in a C++ compiler(like Microsofts Intro ...

  1. #1
    CAP
    CAP is offline
    Registered User CAP's Avatar
    Join Date
    May 2002
    Posts
    179

    Exclamation Definite Answer Needed

    Would somebody please, PLEASE, tell me plain and simple:
    Can C code be compiled in a C++ compiler(like Microsofts Intro one) and can C++ be compiled in a C comiler(I don't think so but just asking).
    If there is anyone who can give me a good answer please tell me.
    -Microsofts Visual C++ Introductory Kit-
    Current Projects: Learning Everything C.

    Everyone has a photographic memory, some people just don't have any film.
    ______________________________

    When was the last time you went for a colon cleansing? Because quite frankly, you're so backed up with crap that it's spilling out your mouth

  2. #2
    Unregistered
    Guest
    C++ is newer than C, so a C++ compiler will handle C, but not necessarily the other way around.

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >Can C code be compiled in a C++ compiler?
    >can C++ be compiled in a C compiler?

    I'm going to say it's down to the compiler. What one are you talking about?

    I have Borland 5.5, which is badged as a C++ compiler, but does C as well.

    I expect that an older C compiler doesn't support C++, but only by reading it's documentation will you know for sure.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  4. #4
    CAP
    CAP is offline
    Registered User CAP's Avatar
    Join Date
    May 2002
    Posts
    179
    I have Microsofts Introductory Edition and so far I am able to compile C code in.
    I was under the impression that C and C++ although similar(the whole superset thing) that they were different but it is working.
    1 thing though, can my compiler handle all C code if it handles some and can I mix and match C and C++ code like:

    printf("whatever")
    and
    cout >> whatever;

    I am not sure about that code(I am learning after all) but can I use 2 different ways of doing something like displaying text in the same program??
    Last edited by CAP; 06-06-2002 at 03:55 PM.
    -Microsofts Visual C++ Introductory Kit-
    Current Projects: Learning Everything C.

    Everyone has a photographic memory, some people just don't have any film.
    ______________________________

    When was the last time you went for a colon cleansing? Because quite frankly, you're so backed up with crap that it's spilling out your mouth

  5. #5
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,600
    A square is a rectangle but not the other way around - right?

    C cannot be c++, because C came first, (1972 actually - me and C are the same age!). C++ was the answer to the beckoning question: "can we make sense of any of this?" refering to the spaghetti-code seventies Ok seriously though, what is the biggest reason for the wide-spread mania over that and other object-oriented/task-oriented languages? Because although C had obvious advantages over it's peers of it's early days, (it was almost as terse as it's asm equivalant and just as capable), it was soon challanged by the up-and-coming so-called OOP languages such as smalltalk and lisp. So a bright young professor named Bjarne Stroustrup combined these capabilities into a stronger, better C that is backward compatible (save for some typing issues/incompatibilities, ...).
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

  6. #6
    Unregistered
    Guest
    C programs have a .c extension, whereas C++ programs have a .cpp extension. I think the header files may be different, as well.

  7. #7
    Registered User billholm's Avatar
    Join Date
    Apr 2002
    Posts
    225

    Exclamation Yep

    C++ is 100% C. But C is a only subset of C++ because there are somethings C++ can do that C can't. Some of these are creation of the so-called "intelligent" objects and (my favorite) polymorphism of its Abstact Data Types.

    Sounds cryptic but is really plain and simple.
    All men are created equal. But some are more equal than others.

    Visit me at http://www.angelfire.com/my/billholm

  8. #8
    Registered User stautze's Avatar
    Join Date
    Apr 2002
    Posts
    195
    >But C is a only subset of C++ because there are somethings C++ can do that C can't.

    You can do do anything in in C that you can you can do in C++. C++ just makes some things easier.

    > C++ is 100% C.

    You said it, not me...

    To answer your question, as long as you are using ANSI C, then any C++ compiler should work. I use gcc and I know it will, but I have no experience with any other compilers.
    'During my service in the United States Congress, I took the initiative in creating the Internet.' - Al Gore, March 9, 1999: On CNN's Late Edition

  9. #9
    *
    Guest
    Any C++ compiler will handle C. C++ is just an extension to the C language (additional libraries and headers, and rules in the IDE), so yes, C must always be supportable.

    No, A C-only compiler will not handle C++. The compiles doesn't have the additional libraries, headers, and languages rules, in order to be able to handle it.

    C++ can do no more than C can. People need to get past their confusion with the language versus what your making the computer do.

    C++ was developed by Bjarne Stroustrup because he is a lazy, undisciplined programmer. As such, he could not tolerate the strict rules in C, as regards abstraction. C doesn't allow abstraction.

    That is the only real difference between C and C++, and again, is solely a language grammer/syntax issue-- NOT a mitigating factor for either language about what you can or cannot make the computer do.

    *LEARN* the difference between the *Language* and the *Chip*.

  10. #10
    Unregistered
    Guest

    Thumbs down

    >C++ was developed by Bjarne Stroustrup because he is a lazy, undisciplined programmer. As such, he could not tolerate the strict rules in C, as regards abstraction. C doesn't allow abstraction.

    Well people, I believe most of you out there will agree that it is a purist's opinion, and a bad one at that.

    Let me remind you that most of the hi-tech games you play now have been programmed using the OOPS theory.

    C++ supports the OOPS theory in the name of technological advancement. Pure C can't do abstraction (we all know that).

    Let me present a challenge:

    If you think that C++ is for lazy people, then try creating a linked list ADT that can support ALL data types. And I mean, ALL. (No compiler directives allowed, only language itself).

    If you just use only C, tough luck. There is no polymorphism in C, hence, you WILL find it very tedious to create a linked list for each and every data type you can imagine. Just think of all the time you will consume creating a list ADT for int, then char, then float, then double.Furthermore there are user-defined types like STUDENTS, then for BANK_ACCOUNT, then for ACCESS_ID, etc...

    Well in C++, just one polymorphic class will answer for all of that. It promotes Rapid Application Development (you know what this means?) Just think of how much time that will save you especially if you are working with a very large and complex project.

    Why don't you try programming a linked list in Assembly instead? It's really dreadful. C is the solution for that. In the same light, C++ is the solution for tiresome jobs in C.

    Hope you learned something, purists. Open up your mind and don't ever talk about laziness again.

  11. #11
    Registered User billholm's Avatar
    Join Date
    Apr 2002
    Posts
    225
    Correct!

    100% C plus A LOT MORE equals and more powerful language. That's precisely why this language is universally called C++. (An increment of C, for arguments' sake)
    All men are created equal. But some are more equal than others.

    Visit me at http://www.angelfire.com/my/billholm

  12. #12
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    > Can C code be compiled in a C++ compiler
    Yes. It is possible.

    > can C++ be compiled in a C comiler
    Technically speaking, no.

    > like Microsofts Intro one
    Microsoft's GUI for the C++ programming language?
    Learn how to use the back door before you use the front door.
    One day the front door might be locked.

    > If there is anyone who can give me a good answer please tell me.
    There is nothing else to be said due to a clumsy question.
    The world is waiting. I must leave you now.

  13. #13
    CAP
    CAP is offline
    Registered User CAP's Avatar
    Join Date
    May 2002
    Posts
    179
    Thanks for the replies(not to mention insults lol) I will try and work some code but one part of my question remains unanswered:
    I know (now) that C can be compiled in a C++ comiler but not reversed and that makes sense but if I can compile C in a C++ compiler than will my compiler complain if I use lets say the C way of showing something with "printf" and then later the C++ with "cout". What will happen if they are the same language.
    -Microsofts Visual C++ Introductory Kit-
    Current Projects: Learning Everything C.

    Everyone has a photographic memory, some people just don't have any film.
    ______________________________

    When was the last time you went for a colon cleansing? Because quite frankly, you're so backed up with crap that it's spilling out your mouth

  14. #14
    Registered User billholm's Avatar
    Join Date
    Apr 2002
    Posts
    225

    Post

    It will only complain if you don't include the proper header files.


    But technically, it is very legal to use C style functions under C++.
    printf's and cout's mix well. But you have to include stdio.h and iostream.h, respectively.

    cout is not in C because it is implemented in with classes and operator overloading. (The operator << is overloaded).

    C++ can handle anything C can dish out. But not all that C++ gives C can swallow.
    All men are created equal. But some are more equal than others.

    Visit me at http://www.angelfire.com/my/billholm

  15. #15
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    > printf's and cout's mix well.
    I can see the spaghetti code now.

    That's very poor form.
    Decide which you are going to use, and stick with one or the other.
    The world is waiting. I must leave you now.

Page 1 of 3 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C Programmers needed for Direct Hire positions
    By canefan in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 09-24-2008, 11:55 AM
  2. how would you answer this question?
    By smoking81 in forum Linux Programming
    Replies: 3
    Last Post: 09-08-2008, 03:53 AM
  3. Looking for constructive criticism
    By wd_kendrick in forum C Programming
    Replies: 16
    Last Post: 05-28-2008, 09:42 AM
  4. getting weird answer when not using ".h"
    By CobraCC in forum C++ Programming
    Replies: 10
    Last Post: 05-07-2003, 06:21 AM
  5. Replies: 22
    Last Post: 11-08-2001, 10:01 PM

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