Yes and No depending upon exactly what you are after.
This question comes up quite a bit.  Here are replys
from previous posts:

-------------------------------------------------------------------

> Do you know if it is possible to reverse C with Rational
> Rose/C++ ?

Technically, yes, but practically, no.  There are no classes in
C (structs only--maybe), and you will not have a package
structure that will show up.  There will be almost no useful
information garnered from a reverse-engineer of C code.  Try it
and see with some of the code; you will see what it looks like.
Results vary depending on customer's coding style.

------------------------------------------------------------------

Yes, Rose can reverse engineer plain old vanilla C.
It will give you whatever classes are in your C code
and nothing else.

Do you see the problem? There is not much there.
Structs become classes, but C does not have
operations in structs. Therefore the classes are not
very interesting. MOST code is ignored.

So you reverse engineer a bunch of stuff and get a blank
(or sparse) model. Not very interesting.

-------------------------------------------------------------------

>Actually, C can be very object oriented if implemented in an OO
>fashion (ex: X-Windows MOTIF).  However, this is rarely the case.
>I think a good exercise would be to run just the header files
>through the Rose Analyzer to get an idea of the code structure.
>It may or may not be valuable.

That is true, and I have coded in that way.  But there is no
"class" key word and no structuring of "attributes" and "methods"
because C is not an OO language.  If C structs could have methods
(functions) then there might be something useful there.  Rose
will ignore stand alone functions.

Rose is not good with some C++ code I have seen because of the
way the code was written.  That is, there were stand alone
functions and a few structures and no real classes in the code.

True, very rare to see C code that would have any aggregate of
structs that would produce anything that looked like a class
diagram.  Even then you would still not know where the functions
went by looking at the diagram.

This question gets asked quite allot.  Just cannot get blood out
of a turnip no matter how hard you squeeze. :-)

-------------------------------------------------------------------

C is not OO, yes indeed. But in the early days people simulated OO
with structs: attributes are fields in the struct and member
operations are function pointers. No polymorphism or encapsulation
all has to be implemented: inheritance, type casting....

 If the code you have is rich of these constructs, it might be
useful to reverse it (I don't think a forward engineer would be a
good idea).

-------------------------------------------------------------------

As a side note, Rose RealTime supports full code generation and
execution in both the C and C++ environments. The C version is for
customers that require C for either historical reasons (interface
to legacy C code), performance reasons, or to reduce dynamic memory
allocation (no news and deletes), but still want the value of high
level OO modelling, full code generation, and host/target based
execution.

The C version uses structs to represent attributes and functions
(that pass pointers to the data structs) as methods. It also allows
you to use OO principles such as inheritance and polymorphism.

RoseRT uses the C++ Analyzer from Rose, so it does not have any
special C reverse engineering capabilities.

-------------------------------------------------------------------

Regarding your question: Is it possible to reverse engineer C code
with Rose?

It is possible with the analyzer to reverse engineer C code
containing structs.
These can be exported to a rose model as if they were classes.
For example, if you have the source code structs.h:

struct my1 {

            int arg1;
            double arg2;
};

struct my2 {

            int arg3;
            my1* ptr;
};

void myfunc(int a, my2* b);

you can load it in the Analyzer, analyze it, choose Export Options
set Detailed Analysis and produce the attached model which will
display the two UML classes my1 and my2, their attributes and a
relationship due to the pointer.(The information about the function
is lost in the model, so if you then regenerate the code from the
model you will lose that part of code).

The relevant option to set in the analyzer (which is automatically
selected if you choose Detailed Analysys Export Option Set) is
accessible in the Analyzer   menu:
Edit->Export Options->Class Model->POD Structs and Unions (POD =
Plain Old Data) There you can choose to represent the PODs as class
when you export to a rose model.

On the other hand, when Forward engineering, you can choose to make
a struct out of a UML class by setting the following property in
Rose:

Class Specification ->C++->Class->ClassKey Struct

-------------------------------------------------------------------

If you only want to document the old C code, you can partly trick
the C++ analyzer in the following way:
by adding a class statement that encloses the whole header file
content. You do not need to modify the file explicitely, you can
add an auxiliary file in the analyzer project. This adding an
explicit class statement is unavoidable, because otherwise you
would lose all the global functions and global data (there's no way
to add an operation or an attribute to a module or to a package in
Rose: only classes can have attributes and operations).
If you do not add the class statement you will only export to rose
the structs, enums, unions as you discovered.

The trick goes as follows:
I have created a project file to which I have added an auxiliary
file:

//myTest.hxx
class myTest{
#include "myTest.h"
};

(I've added the extension .hxx to the project list of extensions)

I have then also added a myTest.h to the project but I have marked
it type 3 so that it is not analyzed independently even if you
select it. The .hxx is instead type 1.

I attach the files to the analyzer project and get the resulting
model obtained by exporting with Detailed Analisys Export Options
set.

This works fine if you limit yourself to reverse engineering the .h
file, which is what normally should be done.

All in all, if you can avoid reversing the .cpp, perhaps you can
still get some useful documentation in this way.

--------------------------------------------------------------------

You can use either Rose Professional C++ Edition or Rose Enterprise
Edition to do this.

There is a partner called 3soft in Germany with the product OO2C
which supports C. Please contact them directly (address on the web
page) for details.

http://programs.rational.com/partner/SearchResults_Company.cfm?CMP=10

-------------------------------------------------------------------

Patrick Kennedy
 Rational Support



On Apr 12, 17:36, Venkatesh Ramanathan wrote:
> Subject: (ROSE) How to include C functions while reverse engineering
>
> Hi,
> I'm trying to reverse engineer C++ classes. Lots of C functions are also
> being used by the code. Whene I reverse
> engineer, I get only C++ classes & their methods.But not the C functions. Is
> there any way to include/represent C functions?
> Thanks for your response
> venkatesh
> _________________________________________________________________
> Get your FREE download of MSN Explorer at http://explorer.msn.com
>
> ************************************************************************
> * Rose Forum is a public venue for ideas and discussions.
> * For technical support, visit http://www.rational.com/support
> *
> * Admin.Subscription Requests: [EMAIL PROTECTED]
> * Archive of messages:
http://www.rational.com/products/rose/usergroups/rose_forum.jtmpl
> * Other Requests: [EMAIL PROTECTED]
> *
> * To unsubscribe from the list, please send email
> *
> * To: [EMAIL PROTECTED]
> * Subject:<BLANK>
> * Body: unsubscribe rose_forum
> *
> *************************************************************************
>-- End of excerpt from Venkatesh Ramanathan


************************************************************************
* Rose Forum is a public venue for ideas and discussions.
* For technical support, visit http://www.rational.com/support
*
* Admin.Subscription Requests: [EMAIL PROTECTED]
* Archive of messages: 
http://www.rational.com/products/rose/usergroups/rose_forum.jtmpl
* Other Requests: [EMAIL PROTECTED]
*
* To unsubscribe from the list, please send email
*
* To: [EMAIL PROTECTED]
* Subject:<BLANK>
* Body: unsubscribe rose_forum
*
*************************************************************************

Reply via email to