473,493 Members | 2,254 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Is C a Object oriented language...?

24 New Member
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):

Expand|Select|Wrap|Line Numbers
  1. int open(const *pathname, int flags);
  2. int open(const *pathname, int flags, mode_t mode);
which is basically a populer feature called Function Overloading of object oriented language only.
Jul 2 '10 #1
10 2111
whodgson
542 Contributor
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.
Jul 2 '10 #2
Banfa
9,065 Recognized Expert Moderator Expert
@whodgson
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.
Jul 2 '10 #3
tyagithehacker
24 New Member
@Banfa
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.
Jul 2 '10 #4
tyagithehacker
24 New Member
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):

Expand|Select|Wrap|Line Numbers
  1. int open(const *pathname, int flags);
  2. int open(const *pathname, int flags, mode_t mode);
which is basically a popular feature called Function Overloading of object oriented language only.
Jul 2 '10 #5
Banfa
9,065 Recognized Expert Moderator Expert
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.
Jul 2 '10 #6
Banfa
9,065 Recognized Expert Moderator Expert
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.
Jul 2 '10 #7
tyagithehacker
24 New Member
@Banfa
hmm it was much clear this time.
thanx a lot... :-)
Jul 2 '10 #8
SinTak
1 New Member
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).
Jul 10 '10 #9
numberwhun
3,509 Recognized Expert Moderator Specialist
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
Jul 12 '10 #10
Banfa
9,065 Recognized Expert Moderator Expert
Note since both threads on this subject have ended up in C++ I have merged them
Jul 12 '10 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1382
by: Vincent Belliard | last post by:
I introduce here a new Object Oriented Language: WO (Wholly Object). The specifications are finished. It's now in development. Several subset of this language have been tested successfully. You...
46
2971
by: ajba74 | last post by:
Hi fellows, I am reading some books to learn the C programming language, and sometimes I have the feeling that when somebody becomes a C expert, he must learn a more modern and object-oriented...
0
7157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7195
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6873
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5453
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4889
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4579
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
285
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.