Core’u geniş Tutki Patlamasın :) (Segmentation Fault Core Dumped C++)

, , , , , , Sende Yorum Yap

İngilizce bilen kardeşler için bir açıklama yapayım :D
( maksat sitenin gavur ziyaretçiside olsun :D )

For English Press 9:

I was coding a small program on C++ then I have the error;
master@slave:~/project/oop2$ g++ MyString.cc MyString.h -o trial
master@slave:~/project/oop2$ ./trial
Segmentation fault (core dumped)

It was because using a pointer without specifying its borders. It grows and grows then it violates the memory addresses belonged by other variables, methods or what ever. The solution is simple just reserving the needed memory. So how to do that? The answer is also simple. You should allocate the memory using malloc() function which is both available in C and C++.

for example you need a pointer to put inside 100 int.
int somenumber = 100; // the number of integer you will put in pointer
int *intPointer;
intPointer = (int *)malloc(somenumber * sizeof(int));
// malloc function needs the byte value of the needed area in memory
// that’s why you should multiply it with the byte value of an integer
// it is generally 4 in 32-bit and 64-bit processor aimed compilers

Don’t press 8 it is for Dutch :D , my Dutch is still poor,
Press 7 for Turkish :)

Evet Türkçesine gelince olayın, Tercüme edin Allah Allah, beni uğraştırmayın :) .
Neyse ben biraz bahsedeyim yine :) ;

Yazdığım programda bir adet int pointer kullanıyordum (çok adet te bir tanesi patlıyordu :) ) ve bu memoryde sınırlarını zorluyordu, hatta altüst edip programımı öldürüyordu. Aslında çok basit bir problem ama yeni başlayanların ve benim gibi unutup tekrar hatırlayanların sık karşılaştıkları ve harşılaşacakları bir problem bu.
Tek yapılması gereken ise işinize yarayacak kadar memory’i o değişken için ayırmanız. Bu işlem için örnek kod yukarda.
Umarım googledan gelen arkadaşların işine yarar, ve bana bol bol ziyaretçi getirir :D

Paylaş - Share :
  • Twitter
  • Facebook
  • LinkedIn
  • del.icio.us
  • Tumblr
  • Diigo
  • StumbleUpon
  • Technorati
  • Google Bookmarks
  • RSS
Alakalı Yazılar - Related Posts:

“Core’u geniş Tutki Patlamasın :) (Segmentation Fault Core Dumped C++)” Yazısına 4 Yorum Var

  1. mehmet ali Says:

    Fani işler İsmail bunlar ….

  2. mehmet ali Says:

    Bir temana gıcık oldum. Elma armut olaylarına girmişin…. Ben blog yazıyom apple a kıl oluyom diye sen apple cı cıkacan yakında. Birde ecnebi memleketinden ucuz apple ile gelirsinde ben seni görürüm…

  3. İsmail Taha Says:

    :D yok abi nerde ecnebilerde ucuz apple verecek göz… Kapitalist bunlar…

    Ama şöyle kelepir bi G5 geçse elime hayır demem yani :D

  4. mehmet ali Says:

    Beleşin gözü kör olsun …

Yorum Yazmayı Unutma

Get Adobe Flash playerPlugin by wpburn.com wordpress themes
WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in