-
Wired all But Not errors
Her is My Code on http://phpfi.com/246425
Everything is Fine If I just remove line 68 and 69
Else Its Showing Wired texts But not errors.
see here is teh Output
Code:
----------------------------------------------
describing pt initialized x = 4 y = 10
describing px returned from pre inc x = 5 y = 11
describing pt after Pre Incrementing x = 5 y = 11
describing py returned from post inc x = 5 y = 11
describing pt after Post Increment x = 6 y = 12
describing pt1 after Init with new x = 80 y = 100
describing pt1 after Pre Incrementing x = 81 y = 101
describing After py += px x = 10 y = 22
describing After py+= pt1 x = 91 y = 123
describing py after py += 2 x = 93 y = 125
describing pt1 After pt1 += 2 x = 0 y = 0
destructing
*** glibc detected *** /root/Desktop/op_overload: double free or corruption (top): 0x0804a018 ***
======= Backtrace: =========
/lib/tls/i686/cmov/libc.so.6[0xb7d6c7cd]
/lib/tls/i686/cmov/libc.so.6(cfree+0x90)[0xb7d6fe30]
/usr/lib/libstdc++.so.6(_ZdlPv+0x21)[0xb7f2ed11]
/root/Desktop/op_overload[0x8048ab8]
/lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xdc)[0xb7d1aebc]
/root/Desktop/op_overload(__gxx_personality_v0+0x4d)[0x80486f1]
======= Memory map: ========
08048000-08049000 r-xp 00000000 08:0a 145784 /root/Desktop/op_overload
08049000-0804a000 rw-p 00001000 08:0a 145784 /root/Desktop/op_overload
0804a000-0806b000 rw-p 0804a000 00:00 0 [heap]
b7c00000-b7c21000 rw-p b7c00000 00:00 0
b7c21000-b7d00000 ---p b7c21000 00:00 0
b7d04000-b7d05000 rw-p b7d04000 00:00 0
b7d05000-b7e40000 r-xp 00000000 08:0a 291032 /lib/tls/i686/cmov/libc-2.5.so
b7e40000-b7e41000 r--p 0013b000 08:0a 291032 /lib/tls/i686/cmov/libc-2.5.so
b7e41000-b7e43000 rw-p 0013c000 08:0a 291032 /lib/tls/i686/cmov/libc-2.5.so
b7e43000-b7e46000 rw-p b7e43000 00:00 0
b7e46000-b7e51000 r-xp 00000000 08:0a 290894 /lib/libgcc_s.so.1
b7e51000-b7e52000 rw-p 0000a000 08:0a 290894 /lib/libgcc_s.so.1
b7e52000-b7e53000 rw-p b7e52000 00:00 0
b7e53000-b7e78000 r-xp 00000000 08:0a 291037 /lib/tls/i686/cmov/libm-2.5.so
b7e78000-b7e7a000 rw-p 00024000 08:0a 291037 /lib/tls/i686/cmov/libm-2.5.so
b7e7a000-b7f59000 r-xp 00000000 08:0a 18744 /usr/lib/libstdc++.so.6.0.8
b7f59000-b7f5c000 r--p 000de000 08:0a 18744 /usr/lib/libstdc++.so.6.0.8
b7f5c000-b7f5e000 rw-p 000e1000 08:0a 18744 /usr/lib/libstdc++.so.6.0.8
b7f5e000-b7f64000 rw-p b7f5e000 00:00 0
b7f74000-b7f77000 rw-p b7f74000 00:00 0
b7f77000-b7f90000 r-xp 00000000 08:0a 290895 /lib/ld-2.5.so
b7f90000-b7f92000 rw-p 00019000 08:0a 290895 /lib/ld-2.5.so
bff0b000-bff20000 rw-p bff0b000 00:00 0 [stack]
ffffe000-fffff000 r-xp 00000000 00:00 0 [vdso]
----------------------------------------------
Program has been terminated receiving signal 6 (Aborted)
But If I use Instead of Object pt It works Fine.
I thought It will Fire Error With Usinfg Without Pointer here
But Why its Pulling glibC ??
-
Code:
pt1 +=2;//For this Line its showing Wired
This calls operator + for a pointer
after that pt1 points to something that is not a Point.
Deleting it crashes.
Kurt
-
>> I thought It will Fire Error With Usinfg Without Pointer here But Why its Pulling glibC ??
You are allowed to add a number to a pointer. It is called pointer arithmetic. However, it does bad things in this example. So the compiler allows it because it trusts you that you want to add a number to the pointer, but then when you try to run the program you get an error because it does bad things.
There are many situations where the compiler trusts you that you know what you are doing. If you do something wrong, it will compile the program and the program will run but do bad things. Sometimes that means it will crash, sometimes it means it will give you incorrect results, sometimes that means it will work for a long time and then fail once when you need it. This is what undefined behavior means.
-
-
I think I've done Pointer Arithmatic before Without knowing what it is in my other Thread.
in this Way *ptr++;
But didnt Understand it Properly.
I've Practical C++ By McGragor
It has a Programm on Pointer Arithmetic But I cant Run it on g++ Linux
Do anyone have any simple example Programm on it that I can Run on my Compiler ??
That Can be compiled on VC++ But I dont have Windows.