Shop OBEX P1 Docs P2 Docs Learn Events
Object Oriented Programming (OOP) with ICCv7 — Parallax Forums

Object Oriented Programming (OOP) with ICCv7

Peter VerkaikPeter Verkaik Posts: 3,956
edited 2008-11-06 16:15 in Propeller 1
Hi,

Attached is a working example using C+ from Quantum Leap
http://www.state-machine.com/devzone/cookbook.htm#OOP
(scroll to bottom of page)

Create folder cplus in ICCv7 install directory and unzip in that folder.
Open project <ICCv7_install_path>\cplus\cplustst\win32\cplustst.prj

main.c is the example application program.
I had to add a dummy putchar() to make it compile
and create output files in folder win32\output

The manual is located in the cplus folder.

Looks like this should provide OOP without too much overhead.
The original zip from the link above is included.

regards peter

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2008-11-06 15:01
    And here is a link to a pdf with indepth info on OOP with C
    (not related to C+ however)
    http://www.planetpdf.com/codecuts/pdfs/ooc.pdf

    regards peter
  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2008-11-06 16:15
    Here is an adapted main.c that includes asio.h·(which provides putchar()).
    That should·output text via propeller pins 30 and 31.

    There is a·cplustst.exe in folder
    <icc_path>\cplus\cplustst\dosb1\release
    Excuting the cplustst.exe from a dosbox you get output:
    name="Circle", area()=3.14, scale(2), name="Circle", area()=12.57, 
    name="Rectangle-0", area()=0.00, scale(2), name="Rectangle-0", area()=0.00, 
    name="Rectangle-1", area()=1.00, scale(2), name="Rectangle-1", area()=4.00, 
    name="Rectangle-2", area()=2.00, scale(2), name="Rectangle-2", area()=8.00, 
    name="Rectangle-3", area()=3.00, scale(2), name="Rectangle-3", area()=12.00, 
    
    

    ·The output from the propeller should be the Hello world part, followed by the above,
    and then whatever you type should be echoed.
    Here is the adapted main.c
    #include <propeller.h>
    #include "shape.h"
    #include "circle.h"
    #include "rect.h"
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <assert.h>
    #include <asio.h>
    enum { NRECT = 4 };
    void main() {
        Circle circle;                    /* Circle instance on the stack frame */
        Circle *c;
        Rect r[noparse][[/noparse]NRECT];
        int i;
        asio_init(57600);
     puts("Hello World!");
        printf("string '%s' string\n", "hello");
     printf("printf works! '%s' %d %c <-- 'a'\n", "string test", 10, 'a');
        
        /* construct objects... */
        Circle_ctor(&circle, "Circle", 1.0);
        c = &circle;
        for (i = 0; i < NRECT; i++) {
            char name[noparse][[/noparse]20];
            sprintf(name, "Rectangle-%d", i);               /* prepare the name */
            Rect_ctor(&r[noparse][[/noparse]i], name, (double)i, 1.0);           /* construct Rect */
        }
                                                         /* test the Circle ... */
        test_area((Shape *)c);
        test_scale(&c->super_);
        test_area((Shape *)c);
        printf("\n");
                                                     /* test the Rectangles ... */
        for (i = 0; i < NRECT; i++) {
            test_area((Shape *)&r[noparse][[/noparse]i]);
            test_scale(&r[noparse][[/noparse]i].super_);
            test_area((Shape *)&r[noparse][[/noparse]i]);
            printf("\n");
        }
                                                        /* destroy objects ... */
        VCALL(Object, xtor, c)END_CALL;  /* destroy the Circle, dynamic binding */
        for (i = 0; i < NRECT; i++) {
            VCALL(Object, xtor, &r[noparse][[/noparse]i])END_CALL;    /* destroy the Rectangles ...*/
        }
        
     while (1)
      putchar(getchar());
    }
    
    


    regards peter

    Post Edited (Peter Verkaik) : 11/6/2008 4:28:30 PM GMT
    c
    c
    4K
Sign In or Register to comment.