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

Re: [ns] new headers



Good morning-

I think that the problem is that you are not getting the address of the right
thing with the & operator. When the offset() function returns its value on the
stack, you're trying to bind that temporary value which is invalid. Another way
to look at it is that the c++ reference operator, while *implemented* as a
pointer, is not *syntactically* a pointer; which is what the bind function
wants.

If you want to do something like this change your function to
	inline static int *offset_ptr { return &offset_; }
then
	bind_offset(hdr_x::offset());

Also, I don't know what you intend by making offset_ static; but that may not be
what you want.

Hope that helps!
-Eric

> I defined a header like this:
> 
> struct hdr_x{
> 
>         int x_;
>         int& x(){ return x_; }
> 
>         static int offset_;     // offset for this header
> 
>         inline static int& offset() { return offset_; }
>         inline static hdr_ebn* access(Packet* p) {
>                 return (hdr_ebn*) p->access(offset_);
>         }
> 
> };
> 
> And then defined the OTcl clas like:
> 
> static class XHeaderClass : public PacketHeaderClass {
> public:
>         XHeaderClass() : PacketHeaderClass("PacketHeader/X",
>                                              sizeof(hdr_x)) {
>                 bind_offset(&hdr_x::offset());
>         }
> } class_xhdr;
> 
> On compiling, it doesnt give errors. On linking it gives the following it
> gives:
> 
> proto-x.o: In function `hdr_x::offset(void)':
> proto-x.o(.hdr_x::gnu.linkonce.t.offset(void)+0x4): undefined reference
> to `hdr_x::offset_'
> collect2: ld returned 1 exit status
> make: *** [ns] Error 1
> 
> Help will be appreciated
> 
> Debo

--------------------------------------------
 Eric H. Weigle   CCS-1, RADIANT team
 [email protected]     Los Alamos National Lab
 (505) 665-4937   http://home.lanl.gov/ehw/
--------------------------------------------