Is C a Object oriented language...?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tyagithehacker
    New Member
    • Jul 2010
    • 24

    Is C a Object oriented language...?

    C is basically a non-object oriented language, then while doing system programming in UNIX why we have two different versions of OPEN function (system call):

    Code:
    [I]int open(const *pathname, int flags);
    int open(const *pathname, int flags, mode_t mode);[/I]
    which is basically a populer feature called Function Overloading of object oriented language only.
  • whodgson
    Contributor
    • Jan 2007
    • 542

    #2
    Many people say that C is a subset of C++. Some say that C++ is a subset of C. It would seem that UNIX system is playing it safe in overloading the open() function.

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #3
      Originally posted by whodgson
      Many people say that C is a subset of C++. Some say that C++ is a subset of C.
      I'm not sure that I have heard anyone say the second. C and C++ are most like siblings with the same parent. C++ supports a lot but not all of the C standard, C definitely doesn't support all of the C++ standard.

      The posted code snippet is not C and will not compile with C. C does not support function overloading and produces these diagnostics

      2: error: conflicting types for 'open'
      1: note: previous declaration of 'open' was here

      Additionally no type is given for pathname.

      Comment

      • tyagithehacker
        New Member
        • Jul 2010
        • 24

        #4
        Originally posted by Banfa
        I'm not sure that I have heard anyone say the second. C and C++ are most like siblings with the same parent. C++ supports a lot but not all of the C standard, C definitely doesn't support all of the C++ standard.

        The posted code snippet is not C and will not compile with C. C does not support function overloading and produces these diagnostics

        2: error: conflicting types for 'open'
        1: note: previous declaration of 'open' was here

        Additionally no type is given for pathname.
        TO BENFA,

        thanx for your reply, but that code is not a part of any executable, it is just the way open() function has been prototyped in unix. and one can use any one of the function as per the requirment, that too without any error.

        actually what i was asking is that why there are two diffrent flavours of open() function, even when we doing system programming in UNIX under C language.

        Comment

        • tyagithehacker
          New Member
          • Jul 2010
          • 24

          #5
          Does system call open() is violating C's principles.

          C is basically a non-object oriented language, then while doing system programming in UNIX why we have two different versions of OPEN function (system call):

          Code:
          [I]int open(const *pathname, int flags);
          int open(const *pathname, int flags, mode_t mode);[/I]
          which is basically a popular feature called Function Overloading of object oriented language only.

          Comment

          • Banfa
            Recognized Expert Expert
            • Feb 2006
            • 9067

            #6
            No you have mis understood. it is not possible for those 2 prototypes to appear in a C program without causing an error because C does not support function overloading.

            If those 2 prototypes appear in the same header which is used for a C compilation then there must be some mechanism that is disabling one of them, conditional of a preprocessor signal for instance or they exist in different header files in which case you can only include one of those 2 headers.

            Because what you have presented is impossible either the question you have asked is based on some falsehood somewhere (i.e. those 2 prototypes do not actually exist) or you have not provided the context that explains how those 2 prototypes can exist.

            If it is the second case then it is that context that will explain why there are 2 flavours of open.

            Comment

            • Banfa
              Recognized Expert Expert
              • Feb 2006
              • 9067

              #7
              It would have helped if you had mentioned that you where quoting documentation and not code. It would also have helped if having quoted documentation you had also gone on and read it all.

              Here is the documentation for open, read it, it will answer your question.

              As it happens open is actually prototyped as a varidac function allowing the 3rd parameter to be optional.

              Comment

              • tyagithehacker
                New Member
                • Jul 2010
                • 24

                #8
                Originally posted by Banfa
                No you have mis understood. it is not possible for those 2 prototypes to appear in a C program without causing an error because C does not support function overloading.

                If those 2 prototypes appear in the same header which is used for a C compilation then there must be some mechanism that is disabling one of them, conditional of a preprocessor signal for instance or they exist in different header files in which case you can only include one of those 2 headers.

                Because what you have presented is impossible either the question you have asked is based on some falsehood somewhere (i.e. those 2 prototypes do not actually exist) or you have not provided the context that explains how those 2 prototypes can exist.

                If it is the second case then it is that context that will explain why there are 2 flavours of open.
                hmm it was much clear this time.
                thanx a lot... :-)

                Comment

                • SinTak
                  New Member
                  • Jul 2010
                  • 1

                  #9
                  It is not function overloading. C allows variadic arguments, so that you can have a function with one or more arguments. The function called is always the same, but it can be aware of the fact that there must be a third argument, and pick it. In the "open" case, it depends on "flags" argument. If you use O_CREAT, and you don't provide the third argument, the compiler can't complain, while the function "thinks" that there's a third argument, and strange "undefined behaviour" things can happen (likely you get a "random" mode for your created file).

                  Comment

                  • numberwhun
                    Recognized Expert Moderator Specialist
                    • May 2007
                    • 3467

                    #10
                    You need to post your questions in the correct forum. There is a C/C++ forum, that is where this question should have been asked.

                    I am moving this question there, but please be mindful of where you are posting in the future.

                    Regards,

                    Jeff

                    Comment

                    • Banfa
                      Recognized Expert Expert
                      • Feb 2006
                      • 9067

                      #11
                      Note since both threads on this subject have ended up in C++ I have merged them

                      Comment

                      Working...