Class-C

Documentation

Introduction.pdf
Specification.pdf

Links

GitHub repo of the language
GitHub repo of the compiler
Discussion board

Example projects

The Class-C compiler
DynamicsX dynamics engine

Written in Class-C

Cerebral Cortex for iOS
Cerebral Cortex for Mac
Cerebral Cortex for BB10

Creator

Milan Toth / milgra

email
homepage
twitter
facebook
google+



The Object-Orineted ISO C

Class-C

What? Another Object-Oriented C language? Why do we need another?

C is a really simple and minimalistic language, that's why we love it. But C++ and Objective-C became language monsters with over a 100 keywords and confusing features, and more confusing libraries. Just because you need classes and objects, you don't have to overcomplicate things.

Minimalism

The idea behind Class-C is very simple : take your existing C code, put global variables and functions in a block and global variables become member variables, functions become methods. Class is ready.

Speed

Explicit method calls are translated to direct c function calls. Dynamic casting is just a few cpu cycles.

Class Merging

Instead of hierarchical inheritance, merge classes freely in a flat structure. If you have overridden a method, but for some reason you need the original one, you can call the original method on your object with an explicit call.

Productivity

The Class-C compiler generates header files automatically, you can concentrate on the implementation. With CLObject as a base class, memory management becomes really simple, just retain/release ownership to objects.

Philosophy

Class-C encourages openness and simplicity. Clean, small, open and well documented code is the safe and reliable code.

License

Class-C and the Class-C compiler are in the public domain.

Creator

Class-C is developed by Milan Toth





QuickStart Guide

Class-C compiler is a source-to-source compiler in its actual state, it produces C source files.

1. Compile the compiler

Download clcc.c , compile it with your favorite c compiler. With gcc or clang it looks like this :

gcc clcc.c -o clcc

clang clcc.c -o clcc

The binary "clcc" appeared in the actual folder. Now you have a working Class-C compiler on your system. You might want to put it under a default system path to make it accessible from anywhere.

2. Compile your first class

Download FirstClass.clc to the same folder, and compile it with clcc :

./clcc FirstClass.clc

Two files with the default names clcsrc.h and clcsrc.c appeared in the folder, these are the compiled c sources of FirstClass.clc.

3. Include the compiled c source in a c file, use FirstClass, and create a binary.

Download main.c to the same folder, and compile your sources with your favorite c compiler. With gcc :

gcc main.c clcsrc.c -o firstprog

main.c inlcudes clcsrc.h and instantiates FirstClass, calls one of its methods, cleans up and exits. Note that main.c uses bridged Class-C calls, these expression looks different in Class-C, it's just for the quickstart.

4. Run your first program

On Unix-like systems, type
./firstprog

The output should be :

Hello, this is FirstClass!!!



How to develop in Class-C?

You can develop Class-C on every platform with a C compiler.

1. Put the compiler under one of your PATH locations

On UNIX-like systems just copy it under /usr/bin or /usr/local/bin

2. Use your favorite C code editor/IDE

You can go on in an old school way, with a plain text editor and command line compiling, or you can use your favorite IDE with C syntax highlighting. If your IDE supports build phases and script running, add Class-C file compiling as the first phase. If build phases aren't supported, you have to create a compile script first, or do the compiling manually before building.

3. Always check compiler output

The compiler output is your best friend, always check it before compiling the final project. You will see which classes are not found, you will get possibly unincluded but needed classes, and so on.

4. Debug your code

Your IDE/Terminal will show the problem in the compiled C source, and you have to find it in the Class-C source. The method name in the compiled source tells you which Class-C class and what method contains the problematic line.



Sneak Peek

Class Definition

  BigPerson:Person:AnotherClass
  {
    CLString* name;
    void sayHello( )
    {
      printf( "Hello" );
    }
  }
				

Alloc/Init/Dealloc

  CLString* name = CLString:alloc( );
  name.initWithCString("milan");
  name.release( );
  
  or

  CLString* name;
  name:alloc( );
  name.initWithCString("milan");
  name.release( );
				

Polymorphism

  BigPerson:Person:ITalk
				

Instance method call

  string.method( arg );
  string:method( arg );
  CLString:method( string, arg );
				

Class/Static method call

  CLString:method( NULL );