C or C++

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Carmen Sei

    #1

    C or C++

    if I need to write C++, I will be forced to learn C automatically?

    Since I saw many C++ code need to call C library also.

    Most program use a combination of C++ code and calling C functions.

    Then writting C++, I cannot avoid learning C right?
  • Alf P. Steinbach

    #2
    Re: C or C++

    * Carmen Sei:
    if I need to write C++, I will be forced to learn C automatically?
    >
    Since I saw many C++ code need to call C library also.
    >
    Most program use a combination of C++ code and calling C functions.
    >
    Then writting C++, I cannot avoid learning C right?
    You will learn some aspects of C. You will not learn C. C++ is a different
    language, and valid C code is seldom valid C++ code except where it's written to
    the common subset (e.g. in header files meant to work with both languages).

    For guidance about learning C++, see the FAQ.


    Cheers, & hth.,

    - Alf

    Comment

    • Christopher

      #3
      Re: C or C++

      On Apr 9, 12:31 pm, Carmen Sei <fatwallet...@y ahoo.comwrote:
      if I need to write C++, I will be forced to learn C automatically?
      False
      Since I saw many C++ code need to call C library also.
      If a C++ library calls a C function under the covers, it does not mean
      you need to know C. If _you_ call a C function than you might, but if
      a "C++ library" _forces_ you to call a C function, it is not a "C++
      library"
      Most program use a combination of C++ code and calling C functions.
      Really? how many years have you spent reading g the source code of
      every library in existence?
      Maybe you could say that the slim amount of programs that you've
      examined the source code for do so. But that doesn't mean that those
      programs were written well or that they set a global precedent.
      Then writting C++, I cannot avoid learning C right?
      False

      Comment

      • lbonafide@yahoo.com

        #4
        Re: C or C++

        On Apr 9, 12:39 pm, "Alf P. Steinbach" <al...@start.no wrote:
        C++ is a different
        language, and valid C code is seldom valid C++ code except where it's written to
        the common subset (e.g. in header files meant to work with both languages)..
        Really? What do you mean by "valid C++"? I would think most C
        programs would compile with a C++ compiler, unless they use keywords
        introduced in C++ as identifiers (e.g. new, delete).

        Comment

        • osmium

          #5
          Re: C or C++

          "Carmen Sei" writes:
          if I need to write C++, I will be forced to learn C automatically?
          >
          Since I saw many C++ code need to call C library also.
          >
          Most program use a combination of C++ code and calling C functions.
          >
          Then writting C++, I cannot avoid learning C right?
          That's a difficult question to answer briefly. I suggest you browse around
          on the page in the link, looking at things that seem to be germane to your
          question. My brief answer would be that only a beginner or superficial C++
          programmer does not also know C.

          http://www.research.att.com/~bs/bs_faq.html#C-is-subset


          Comment

          • Alf P. Steinbach

            #6
            Re: C or C++

            * lbonafide@yahoo .com:
            On Apr 9, 12:39 pm, "Alf P. Steinbach" <al...@start.no wrote:
            >
            >C++ is a different
            >language, and valid C code is seldom valid C++ code except where it's written to
            >the common subset (e.g. in header files meant to work with both languages).
            >
            Really?
            Yes.

            What do you mean by "valid C++"?
            The C programming language is defined by a set of international standards.

            Usually when we refer to "C" we mean the previous standard, C89 (a.k.a. C90).

            I would think most C
            programs would compile with a C++ compiler, unless they use keywords
            introduced in C++ as identifiers (e.g. new, delete).
            You're right that unless a C program is invalid as C++, it's valid.

            And depending on your definition of "most" the complete sentence might arguably
            be trivially true.

            However, it doesn't seem like a very meaningful comment.

            Also, it indicates a belief that a program doesn't use any C++ specific keywords
            will be valid C, or that a program that is syntactically valid as both C and C++
            will necessarily be valid as both C and C++ program.

            That belief is incorrect.


            Cheers, & hth.,

            - Alf

            Comment

            • Eric Johnson

              #7
              Re: C or C++

              On Apr 9, 10:31 am, Carmen Sei <fatwallet...@y ahoo.comwrote:
              if I need to write C++, I will be forced to learn C automatically?
              >
              Since I saw many C++ code need to call C library also.
              >
              Most program use a combination of C++ code and calling C functions.
              >
              Then writting C++, I cannot avoid learning C right?
              Yes and no. C++ is based on C, so naturally there is a large amount
              of overlap between the two languages. In learning C++, you will also
              learn some aspects of C programming. In my experience, there are many
              C++ programmers who learned C before C++, so they tend to use C-style
              even when writing C++. It may benefit your programming career to at
              least become familiar with the C standard library and to become
              familiar with C, so when you encounter C++ written in a more
              traditional C style you will not have as much trouble understanding
              it.

              If your goal is to learn C++, I would recommend concentrating on
              learning the best practices for C++ first and learning C as a 2nd
              priority.

              Comment

              • Ian Collins

                #8
                Re: C or C++

                lbonafide@yahoo .com wrote:
                On Apr 9, 12:39 pm, "Alf P. Steinbach" <al...@start.no wrote:
                >
                >C++ is a different
                >language, and valid C code is seldom valid C++ code except where it's written to
                >the common subset (e.g. in header files meant to work with both languages)..
                >
                Really? What do you mean by "valid C++"? I would think most C
                programs would compile with a C++ compiler, unless they use keywords
                introduced in C++ as identifiers (e.g. new, delete).
                No, there are a number of differences between C and the C like subset of
                C++. The most common difference is automatic conversion from void* to
                any pointer type. This makes the idiomatic C form

                T* p = malloc(someSize )

                illegal in C++.

                There are many more.

                --
                Ian Collins.

                Comment

                • lbonafide@yahoo.com

                  #9
                  Re: C or C++

                  On Apr 9, 2:13 pm, Ian Collins <ian-n...@hotmail.co mwrote:
                  lbonaf...@yahoo .com wrote:
                  On Apr 9, 12:39 pm, "Alf P. Steinbach" <al...@start.no wrote:
                  >
                  C++ is a different
                  language, and valid C code is seldom valid C++ code except where it's written to
                  the common subset (e.g. in header files meant to work with both languages)..
                  >
                  Really?  What do you mean by "valid C++"?  I would think most C
                  programs would compile with a C++ compiler, unless they use keywords
                  introduced in C++ as identifiers (e.g. new, delete).
                  >
                  No, there are a number of differences between C and the C like subset of
                  C++.  The most common difference is automatic conversion from void* to
                  any pointer type.  This makes the idiomatic C form
                  >
                  T* p = malloc(someSize )
                  >
                  illegal in C++.
                  >
                  There are many more.
                  I stand educated.

                  Comment

                  • Ioannis Vranos

                    #10
                    Re: C or C++

                    Carmen Sei wrote:
                    if I need to write C++, I will be forced to learn C automatically?
                    >
                    Since I saw many C++ code need to call C library also.
                    >
                    Most program use a combination of C++ code and calling C functions.
                    >
                    Then writting C++, I cannot avoid learning C right?

                    With minor exceptions C95 (ISO/IEC 9899:1995) is a subset of C++
                    (ISO/IEC 14882:2003). More accurately it is almost the entire functional
                    paradigm subset of C++ (C++ supports 4 paradigms completely, the
                    functional paradigm, the object oriented paradigm, the generic
                    programming paradigm (templates), and the modular paradigm (namespaces).

                    Each paradigm is supported well with close to optimal space and time
                    efficiencies.

                    If the question is about learning C before C++, it is not needed.
                    Actually it is not recommended. Learn C++ only if you do not need to
                    know C programming.

                    Currently C (ISO/IEC 9899:1999) and C++ (ISO/IEC 14882:2003) are two
                    different languages.

                    Comment

                    • Ioannis Vranos

                      #11
                      Re: C or C++

                      Clarification:


                      Ioannis Vranos wrote:
                      Carmen Sei wrote:
                      >if I need to write C++, I will be forced to learn C automatically?
                      >>
                      >Since I saw many C++ code need to call C library also.
                      >>
                      >Most program use a combination of C++ code and calling C functions.
                      >>
                      >Then writting C++, I cannot avoid learning C right?
                      >
                      >
                      With minor exceptions C95 (ISO/IEC 9899:1995) is a subset of C++
                      (ISO/IEC 14882:2003). More accurately it is almost the entire functional
                      paradigm subset of C++ (C++ supports 4 paradigms completely, the
                      functional paradigm, the object oriented paradigm, the generic
                      programming paradigm (templates), and the modular paradigm (namespaces).
                      >
                      Each paradigm is supported well with close to optimal space and time
                      efficiencies.
                      >
                      If the question is about learning C before C++, it is not needed.
                      Actually it is not recommended. Learn C++ ==alone if you do not need to
                      know C programming.
                      >
                      Currently C (ISO/IEC 9899:1999) and C++ (ISO/IEC 14882:2003) are two
                      different languages.

                      Comment

                      • Ian Collins

                        #12
                        Re: C or C++

                        Ioannis Vranos wrote:
                        Carmen Sei wrote:
                        >if I need to write C++, I will be forced to learn C automatically?
                        >>
                        >Since I saw many C++ code need to call C library also.
                        >>
                        >Most program use a combination of C++ code and calling C functions.
                        >>
                        >Then writting C++, I cannot avoid learning C right?
                        >
                        >
                        With minor exceptions C95 (ISO/IEC 9899:1995) is a subset of C++
                        (ISO/IEC 14882:2003).
                        No, they are not "minor exceptions".

                        --
                        Ian Collins.

                        Comment

                        • Ioannis Vranos

                          #13
                          Re: C or C++

                          Ian Collins wrote:
                          Ioannis Vranos wrote:
                          >Carmen Sei wrote:
                          >>if I need to write C++, I will be forced to learn C automatically?
                          >>>
                          >>Since I saw many C++ code need to call C library also.
                          >>>
                          >>Most program use a combination of C++ code and calling C functions.
                          >>>
                          >>Then writting C++, I cannot avoid learning C right?
                          >>
                          >With minor exceptions C95 (ISO/IEC 9899:1995) is a subset of C++
                          >(ISO/IEC 14882:2003).
                          >
                          No, they are not "minor exceptions".

                          Supposing you are not talking about the word "exception" , the exceptions
                          I know are the following:


                          1. Not implicit void * to any other pointer type conversion, as in C95.
                          2. 'a' is a char in C++ and not an int as in C95.
                          3. 0 is to be preferred than NULL, which does not apply to C95.
                          4. POD types can be considered as char/unsigned char sequences in C++,
                          but only as unsigned char sequences in C95.
                          5. Empty parentheses in function declarations/definitions are equivalent
                          to void in C++, but is a different thing in C95.


                          (6?) The following is guaranteed to not compile in C95, but it compiles
                          in my C++ compiler, but I am not sure if it is a difference or a
                          compiler-thing:


                          int main(void)
                          {
                          register char array[]= "Test";

                          char *p= array;

                          return 0;
                          }


                          Have I forgotten anything?

                          Comment

                          Working...