Re: Object orientation.....




"Vishal Naidu" <naiduvishal@xxxxxxxxx> wrote
> is it really possible to write object oriented code in C ?
> and if yes how do we achieve abstration, polymorhism , hierarchy etc.
> in C
>
The advantage of using C rather than an object-oriented language is that you
get to decide the protocol.

For instnace you could define a struct OBJECT
typedef struct
{
void **interfaces;
char **interfacenames;
in Ninterfaces;
} OBJECT;

Then you can have a function void *get_interface(OBJECT *obj, char *name)

This queries the object for an interface, and returns it.

eg
typedef struct
{
void *draw(unsigned char *rgb, int width, int height, int x, int y);
} DRAWABLE;

Thus you build your object from interfaces.



.



Relevant Pages

  • Re: string compare
    ... short int length; ... char data; ... I want to create string processing functions like strcmp, ...
    (comp.lang.c)
  • Re: conversion to non-scalar type requested error
    ... int val; ... a char array to a struct. ...
    (comp.lang.c)
  • Re: string compare
    ... I am using custom string structures in a project. ... short int length; ... char data; ...
    (comp.lang.c)
  • [EXPL] AppleFileServer (AFS) FPLoginExt DoS
    ... The following security advisory is sent to the securiteam mailing list, and can be found at the SecuriTeam web site: http://www.securiteam.com ... typedef struct {char PATH;} PATH_T; ... int connect_afp ...
    (Securiteam)
  • Re: string compare
    ... I am using custom string structures in a project. ... short int length; ... char data; ...
    (comp.lang.c)