Welcome to Telelogic Product Support
  Home Downloads Knowledgebase Case Tracking Licensing Help Telelogic Passport
Telelogic TAU (steve huntington)
Decrease font size
Increase font size
Topic Title: How to represent function pointers in TAU 2.7?
Topic Summary:
Created On: 13-Apr-2007 09:43
Status: Read Only
Linear : Threading : Single : Branch
Search Topic Search Topic
Topic Tools Topic Tools
Subscribe to this topic Subscribe to this topic
E-mail this topic to someone. E-mail this topic
Bookmark this topic Bookmark this topic
View similar topics View similar topics
View topic in raw text format. Print this topic.
Answer This question was answered by Jens Abildgaard, on Thursday, April 19, 2007 1:43 PM

Answer:
Representing function pointers through interfaces is only supported by the C++ code generator.

I've found that it is possible to use 'void*' pointers and embedded "C" code when using the "C" code generator.

Here's an example.....

active class Class1 {
statemachine initialize {
Charstring str = "Hello World\n";
'void*' funcPtr;
start {
{
{
[[ #(funcPtr) = (void*)printf; ]] // Assign printf() to the funcPtr attribute
[[ ((int (*)(char*))#(funcPtr))(#(str)+1);]] // call printf indirectly through funcPtr
}
}
nextstate Idle;
}
state Idle;
for state Idle;
}
}

Cheers,
Jens
 13-Apr-2007 09:43
User is offline View Users Profile Print this message


Hemanth Kumar R

Posts: 2
Joined: 13-Apr-2007

Is there any way to represent function pointers inside the model using C code gernerator?
In the TAU help I found how to map from C/C++ to UML:

C/C++: 
typedef int (*PFunc) ( int );

UML: 
public <<operationReference>> interface PFunc {
  int call( int);
}

But when I tried this example, I got the following error:
PFunc Error TSC0401: When generating C code, operation references are not supported.

Please help. Thanks.

Report this to a Moderator Report this to a Moderator
 13-Apr-2007 19:55
User is offline View Users Profile Print this message


Jens Abildgaard

Posts: 1
Joined: 3-Jun-2003

Answer Answer
Representing function pointers through interfaces is only supported by the C++ code generator.

I've found that it is possible to use 'void*' pointers and embedded "C" code when using the "C" code generator.

Here's an example.....

active class Class1 {
statemachine initialize {
Charstring str = "Hello World\n";
'void*' funcPtr;
start {
{
{
[[ #(funcPtr) = (void*)printf; ]] // Assign printf() to the funcPtr attribute
[[ ((int (*)(char*))#(funcPtr))(#(str)+1);]] // call printf indirectly through funcPtr
}
}
nextstate Idle;
}
state Idle;
for state Idle;
}
}

Cheers,
Jens
Report this to a Moderator Report this to a Moderator
 19-Apr-2007 13:44
User is offline View Users Profile Print this message


Hemanth Kumar R

Posts: 2
Joined: 13-Apr-2007

Thank you Jens.
Report this to a Moderator Report this to a Moderator
Statistics
20925 users are registered to the Telelogic TAU forum.
There are currently 1 users logged in.
The most users ever online was 15 on 31-Mar-2008 at 16:22.
There are currently 0 guests browsing this forum, which makes a total of 1 users using this forum.
You have posted 0 messages to this forum. 0 overall.

FuseTalk Standard Edition v3.2 - © 1999-2009 FuseTalk Inc. All rights reserved.