[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [ns] passing lists in pkt header between C++ and OTcl
> The list can consist of nothing, one number, or a list of numbers. I know
> how to create this in OTcl. The problem is when I call the 'recv'
> function in C++ space. If the OTcl list is "" (null), then I get an error
> message when I call an OTcl function using the C++ sprintf function which
> calls the OTcl 'recv' using '%s' for the null field.
>
> Maybe the above sounds confusing, here is the code from the C++ side:
> sprintf(out, "%s recv %s", name(), hdr->myList);
> And from the OTcl side:
> Agent/myAgent instproc recv { myList } {
> And the 'send' from the OTcl side:
> set thisList ""
> lappend thisList "."
> $newAgent send $thisNeighbor $thisList
I'm not sure if I understand your question correctly, but:
(a) if you want
to pass arbitrary number of args from otcl to c++ (which is essentially a
list), you know how many args there are by argc in command(), so you can
handle 0/many argument cases conditionally;
(b) if what you are saying is that hdr->myList can be a NULL so
your c++ part will core dump due to incorrect handling in sprintf(), then
can you do a conditional check to see if myList is empty?
(c) if what you said is $thisList is passed to c++ as a single argument,
which can be empty, then perhaps you want to do something like
$newAgent send $thisNbr [join $thisList] (there is more elegant way to do
this, but join is the most straightforward I can think of now...)
then c++ code will see it as multiple arguments then you can handle it
through argc.
Hope this helps.