First release libooc-0.0.1

18 07 2008

This is the first public release of libooc. So far it’s only a experiment and not used in any practical application. In reallity it’s even not yet a library. It’s simply a test application which could later be changed to a library.

The idea of libooc is taken from a book that I bought some years ago:

Objektorientierte Programmierung mit ANSI C
Axel-Tobias Schreiner
ISBN 3-446-17426-5
Carl Hanser Verlag

This shows how to implement a object oriented framework in ANSI C. I liked to idea and now had some time to create some code. So far only parts of the String class is implemented. The idea is to reimplement the C++ STL in ANSI C.

But see here for an easy test application (also included in the package below):

#include "OOC_Class.h"
#include "OOC_String.h"

int main (int argc, char **argv)
{
  OOC_String_t *a = OOC_Class_new (OOC_String, "Class A");
  OOC_String_t *aa = OOC_Class_clone(a);
  OOC_String_t *b = OOC_Class_new (OOC_String, "Class B");

  printf("ooc_sizeof(a) == %u\n", OOC_Class_sizeof(a));

  if (OOC_Class_differ(a, b))
    printf ("ok");

  if (OOC_Class_differ(a, aa))
    printf ("differ?");

  if (a == aa)
    printf ("clone?");

  OOC_String_append (a, " is the best!");

  printf ("a: %s\n", OOC_String_c_str (a));

  OOC_String_assign (a, "This is a assigned string!\n");

  printf ("a: %s\n", OOC_String_c_str (a));

  OOC_String_erase (a);

  printf ("a: %x\n", OOC_String_c_str (a)[0]);

  printf ("OOC_String_empty (a): %s\n", OOC_String_empty (a) ? "true" : "false");

  OOC_String_assign (a, "This is a new assigned string!");

  printf ("OOC_String_length (a): %d\n", OOC_String_length (a));

  printf ("at (a): %c\n", *OOC_String_at (a, 3));

  OOC_String_append_ooc (a, b);

  printf ("OOC_String_append_ooc (a): %s\n", OOC_String_c_str (a));

  OOC_Class_delete(a), OOC_Class_delete(aa), OOC_Class_delete(b);

  return 0;
}

Not sure if this is usable in any real applications. But I think the pain of the C string handling is hidden very well behind the OOC principle. What do you think? Do you think this is usable in any real world application? Does it worth to go forward with reimplementing the STL classes in ANSI C? Give me a feedback if you like.

Get it here:
libooc-0.0.1.tar.gz

Advertisements

Actions

Information

2 responses

17 01 2009
[libooc] OO in ANSI C | hilpers

[…] mit Strings arbeiten musste und mir das nicht wirklich Spaß macht. Das ist dabei raus gekommen: https://andreasvolz.wordpress.com/200…se-libooc-001/ In einem Beispiel-Programm finde ich den Stil mit C Strings zu arbeiten recht schön. Wie verhält […]

11 06 2012
Kristoffer Berggren

Just want to submit a tip, about my c-code blog, for people that are intressted. c-code.org dedicated to tricks and tips about C coding.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: