[aspectc-user] pointer bug?
Olaf Spinczyk
Olaf.Spinczyk at informatik.uni-erlangen.de
Mon Feb 2 11:47:45 CET 2004
Hi,
shyam sunder wrote:
> Pointers seems all messed up. Have a look:
>
> main.acc:
>
> #include <cstring>
> #include <iostream>
>
> void foo(void* x)
> {
> cout << "in foo: " << x << endl;
> }
>
> int main()
> {
> char x[]="asdf";
> cout << "in main: " << (void*)x << endl;
> foo(x);
> }
>
> ------------------------------------------------
> Test.ah:
>
> #include <iostream>
>
> aspect Test
> {
> public:
> pointcut method1() = call("% foo(...)");
>
> advice method1() : before()
> {
> cout << "in aspect: " << (tjp->arg(0)) << endl;
> }
> };
>
> -----------------------------------------------
>
> ac++ -p. -c main.acc -o main.cpp
> g++2 main.cpp
>
> output:
>
> in main: 0xbffff7d0
> in aspect: 0xbffff7b0
> in foo: 0xbffff7d0
>
> -----------------------------------------------
>
> Whats wrong with this picture?
It is no error. In main and foo you print the address of the first
character in your array while tjp->arg(0) is a pointer to this pointer.
If you want to print the string in the aspect, use:
cout << *(char**)tjp->arg(0) << endl;
Regards,
Olaf
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3142 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://www.aspectc.org/pipermail/aspectc-user/attachments/20040202/1d629d00/attachment.bin>
More information about the aspectc-user
mailing list