Many of my friends know that the C language can be used to implement object-oriented programming, but the specific details of the operation are a bit confused. Therefore, based on the study of LW_OOPC, the author makes full simplification of LW_OOPC. It only retains the most basic object-oriented functions and forms its own OOSM macro package. In fact, these things are enough, the source code of the OOSM macro package is as follows: [cpp]/* Object-Oriented Support Macros (OOSM) OOSM is an object-oriented support macros, it makes the C programming language with object-oriented programming capabilities. LW_OOPC ( http://sourceforge.net/projects/lwoopc/ ) Means Light-weight Object-Oriented Programming in C, written by MISOO team, it is a very outstanding works! OOSM inherits the essence of LW_OOPC and crops to retain the basic features. OOSM written by Turingo Studio, but anyone can copies modifies, and distributes it freely. hansome Sun (hansome.sun@gmail.com) January 18,201 3 */# ifndef _ OOSM_H _ # define _ OOSM_H _ # include <stdlib. h> # define class (type) \ typedef struct type; \ type * type ##_ new (void); \ void type ##_ constructor (type * t ); \ int typ E ##_ destructor (type * t); \ void type ##_ delete (type * t); \ struct type # define interface (type) \ typedef struct type; \ struct type # define extends (type) type # define implements (type) type # define constructor (type) \ type * type ##_ new (void) \ {\ type * this; \ this = (type *) malloc (sizeof (type); \ if (this = NULL) return NULL; \ type ##_ constructor (this); \ return this ;\}\\ void ty Pe ### constructor (type * this) # define destructor (type) \ void type ##_ delete (type * this) \{\ if (type ##_ destructor (this) free (this) ;\}\\ int type ##_ destructor (type * this) # define mapping (tf, sf) this-> tf = sf # endif/* _ OOSM_H _ */less than 30 lines of real code, you can intuitively realize that the cost of implementing object-oriented in C language is very low. Supported by the OOSM macro package, the C language code can be so elegant and compact: [cpp] # include <stdio. h> # include "imeas. h "# include" ccirc. h "# include" crect. h "# include" csqua. h "int main (int argc, char * argv []) {ccirc * c = ccirc_new (); crect * r = crect_new (); csqua * s = csqua_new (); c-> radius = 9.23; r-> width = 23.09; r-> height = 78.54; s-> crect. width = 200.00; printf ("Circle: (% lf, % lf, % lf) \ n", c-> diam (c), c-> imeas. peri (c), c-> imeas. area (c )); Printf ("Rectangle: (% lf, % lf) \ n", r-> imeas. peri (r), r-> imeas. area (r); printf ("Square: (% lf, % lf) \ n", s-> crect. imeas. peri (s), s-> crect. imeas. area (s); ccirc_delete (c); crect_delete (r); csqua_delete (s); return 0 ;}so How do ccirc/crect/csqua and other objects describe, see the next set decomposition.