Modelling a procedural language

Started by
4 comments, last by Rajveer 17 years ago
Hi guys, I'm using C to program for my 3rd year university project and am in the stage of designing my program. I've been looking at UML since I've read that it can be used to model procedural programs, although by nature it's more useful for object oriented approaches, but cannot find anything helpful for UML and procedural languages. Which modelling technique would you guys recommend me using for modelling procedural languages? [Edited by - Rajveer on April 8, 2007 5:35:59 PM]
Advertisement
flow chart,
would probably not want to model everything since you'd have a very big chart but it could be useful for some key functions
You know you can program in an object oriented fashion in C, its just you don't get any language support for it. If you are used to dealing with OO rather than procedural this could help.
Cheers for the replies guys.

@Kaze: I've been using flowcharts for some things, such as the main flow of the program and some key functions, and it's working very well. It's just that I'm not sure if a flowchart method would be acceptable as a higher level modelling language? If however it is then I'd be more than happy to continue with this!

@rip-off: Are you referring to ObjC? In standard C, how would one code objectively (is that the right word?) keepings things such as inheritance? (Any websites or anything?) I'm not more or less comfortable wiht an OO approach but it does sound interesting!
Quote:Original post by Rajveer
@rip-off: Are you referring to ObjC? In standard C, how would one code objectively (is that the right word?) keepings things such as inheritance? (Any websites or anything?) I'm not more or less comfortable wiht an OO approach but it does sound interesting!

Standard C. As I mentioned, you don't get any language support [smile]

Encapsulation can be forward declaration and use of types via opaque pointers.

Inheritance can modelled be aggregation.

Polymorphism can use function pointers, optionally using a vtable style approach.

In general, a class in the form
class Foo : public Bar{public:    Foo( args... );    ~Foo();    void something();    virtual void somethingElse();private:    int member;};


Could be represented like:
/* foo.h */struct Bar;struct Foo;Foo *createFoo( args... );void destroyFoo( Foo * );/* up cast */Bar *barFromFoo( Foo * );void Foo_something( Foo * );void Foo_somethingElse( Foo * );/* foo.c */typedef void (*VFuncPtr)();struct Foo{    Bar bar;    VFuncPtr somethingElse;    int member;};/* base virtual function implementation */static void Foo_privateSomethingElse( Foo * ){/*...*/}Foo *createFoo( args... ){   // malloc a foo   // init its members   // set foo->somethingElse = &Foo_privateSomethingElse;}void destroyFoo( Foo * ){    // destroy members    // free() foo ptr}/* cast */Bar *barFromFoo( Foo *self ){    return &self->bar;}void Foo_something( Foo *self ){    // same as C++, but using explicit self pointer     // instead of implicit this}void Foo_somethingElse( Foo *self ){   // a subclass of foo could initialise self->somethingElse   // to point to a different function in its own source file perhaps.   // we might have to have a function to allow someone to set this though   // probably an extended constructor...   foo->somethingElse();}


Its really as complicated as you want to make it. But you'd have to argue why you'd be using C rather than C++ if you were to go down that route.
Oh right, I see! Cheers for that information :) Although I do agree with you, if you're going to imitate features that you get for free in C++ then you may as well use C++ in the first place.

So it's the general opinion that flowcharts are one of the most efficient ways to model a procedural application?

This topic is closed to new replies.

Advertisement