[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [oc] Vera Query




----- Original Message -----
From: <vlsi_champ@indiatimes.com>
To: <cores@opencores.org>
Sent: Wednesday, October 30, 2002 3:35 AM
Subject: [oc] Vera Query


> Hello Friends,
>
> In Vera, I have some queries.
>
> Suppose there are two classes defined; with one task in each, say,
> class1 has a task defined task1,
>  and class2 has a task defined as task2.
>
> Now, can task1 be called in task2?
Assuming the rules for Vera follow the rules for C++ then it depends on how
you designed the constructors and functions.

>
> In class2, I have declared an object, say obj1 of type class1, as below:
>                   class class2 {
> class1 obj1;
>      ----
>      ----
>                 task2 ( ) {
>                                       -----
>   ----
>                             obj1.task1( );
>
>                  } //end task2
>
>           }//end class2
>
> Then I called the task1, of class1, as shown above.
> Now the query is that, is this allowed or not? Is there any better way of
> calling task1?
>
> If say, there are more variables and other data types defined in class1.
> Then just by defining an
> object "obj1" of class1, as shown above, do the memory is allocated for
> all these variables and other
> data types in class1?? Or the memory is allocated only for the task1
> which called as shown in the code
> example shown above?
>
> If instead of this, along with defining the object "obj1" it is
> assigned "new" then what difference does
> it make? Like this,
>
>                   class class2 {
> class1 obj1 = new; ////change made

In C++ you cannot use "new" in the declaration of the class (other than in
an inline class function declaration).
Also this (incorrect) statement would be "class1 obj1* = new class1;
////change made"

>      ----
>      ----
>                 task2 ( ) {
>                                       -----
>   ----
>                             obj1.task1( );
>
>                  } //end task2
>
>           }//end class2
>
> Thanks in advance,
>
It is not entirely clear what you are trying to do but it sounds like you
are trying to construct what is called co-routines. If you could be more
clear about your requirements you may get the advise you seek.

In C++ you can call a funciton of a different class by use of a scoping
prefix (<class name>::)

    class1::task1();

However, if you are indeed attempting to construct a task schedular by use
of co-routines you should not call a co-routine using function calls as
illustrated above _unless_ measures are taked such that you will not consume
all of stack space in the process. i.e. the function calls are a quick
in-and-out and do not end up recursing infinately.

BAD CODING EXAMPLE

 class1::task1()
 {
    while(1)
    {
        if(NothingToDo)
            obj2.task2();
        else
            doSomething();
    }
}

 class2::task2()
 {
    while(1)
    {
        if(NothingToDo)
            obj1.task1();
        else
            doSomething();
    }
}

The above example would "dive down the stack" and you would consume all of
stack space

> Regards,
>
> VLSI CHAMP....
> --
> To unsubscribe from cores mailing list please visit
http://www.opencores.org/mailinglists.shtml
>

--
To unsubscribe from cores mailing list please visit http://www.opencores.org/mailinglists.shtml