Does C support inheritance? If so, is it by using struct
s since classes are not defined in C?
Asked
Active
Viewed 5,065 times
5

Mehdi Charife
- 722
- 1
- 7
- 22

ckv
- 10,539
- 20
- 100
- 144
-
No there are doubts that come to your mind sometimes when you read the textbooks. – ckv Jun 06 '10 at 19:13
-
4Inheritance and other OO features _can_ be simulated in C. – Yktula Jun 06 '10 at 19:15
-
1PSA: please stop adding answers that are just variants of "No, C is not object oriented." This has already been covered in 2010. – General Grievance Apr 24 '23 at 13:54
4 Answers
12
Yes, it does. See http://gcc.gnu.org/ml/gcc/2010-05/msg00725.html . See Axel-Tobias Schreiner's book Object-Oriented Programming with ANSI C. There's an English translation of it available.
Also, see Object-orientation in C and How can Inheritance be modelled using C? .
-
Can you add an explanation for the first link? I'm interpreting this as "Yes, you can emulate it, but you really shouldn't." Is that what you were trying to say? – General Grievance Apr 24 '23 at 16:37
8
No, it doesn't. C is not an Object-Oriented language. Inheritance is a property of OO languages.
You should try C++. It's OO and supports much more than inheritance.

General Grievance
- 4,555
- 31
- 31
- 45

Midhat
- 17,454
- 22
- 87
- 114
5
There is no Compiler-level support for inheritance in C. Nevertheless, as others have already pointed out, Object Oriented coding does not REQUIRE such support. However, its a lot easier to write OO code in C++.

swestrup
- 4,079
- 3
- 22
- 33