Kırmızı Şapka

RedHat, Uygulama Kurulumu, Ayarlar vs.

Pazartesi, Temmuz 27, 2009

Tur donusumleri

  1. dynamic_cast

  2. static_cast

  3. reinterpret_cast

  4. const_cast

Etiketler:

Cumartesi, Temmuz 25, 2009

Excel de formul yazimi

Yeni Mac Office'de formulun ucunda cift tiklamak ise yaramiyor utun sutuna ayni formulu uygulamam icin. Asagidaki ilk oneri super.


1 - Enter A10000 in the Name box and hit enter to select A10000.
2 - Scroll up to A1
3 - Hold the shift key while clicking A1 to select A1:A10000.
4 - Type your formula into the formula bar
5 - Hold the Ctrl key and hit enter.

Or,

Enter the formula in A1 and drag it down to A10000.

Or use this code:

Sub FormulaTenK()
Range("A1:A10000").Formula = "=B1*6"
End Sub

Etiketler:

Salı, Temmuz 21, 2009

suse useradd

useradd -m -g users username

useradd -m -G users,

Bu sekilde users grubuna dahil kullanicinin ana dizini de yaratilacak.

Etiketler:

Pazartesi, Temmuz 20, 2009

Eclipse de C++ icin include

Linkteki yaziyi oku. Ozeti:

Project->Properties

C/C++ Build

Settings

Directories

Etiketler:

Çarşamba, Temmuz 15, 2009

Deyim karsiligi

Yerin kulagi vardir:

loose lips can sink ships

Cumartesi, Temmuz 11, 2009

Exception Kullanimi


#include "ConfigException.h"


void test(int t) throw(ConfigException)
{
if (t==4)
{
throw ConfigException("t cannot be 4");
}

}

int main(int argc, char* argv[])
{
try{
if(argc>1){
int input = atoi(argv[1]);
test(input);
}
}
catch (ConfigException& ce) {
cerr<<"Reason: "<< ce.what <<endl;
exit(8);
}
catch (...) {
cerr<<"Unknown error"<<endl;
exit(8);
}
return(0);

}

Etiketler:

Exception


#include <iostream>
#include <cstdlib>
using namespace std;

class ConfigException{

public:
const string what;
ConfigException(const string & i_what): what(i_what){}
};

Etiketler:

Perşembe, Temmuz 09, 2009

GoogleApi

http://download.cnet.com/Google-Web-APIs/3000-10250_4-10506575.html

Uzun sure burada kalacagini umarim

Etiketler:

Abstract Class

"An abstract class can be used to define an interface for which derived classes prvide a variety of implementations.
An abstract class is a class that can be used only as a base class of some other class; no objects of an abstract may be created except as objects representing a base class of a class derived from it. A class is abstract if it has at least one pure virtual function.

An abstract class may not be used as an argument type, as a function return type, or as the type of an explicit conversion."

"As a rule of thumb, declare a virtual destructor in every base class that has a virtual function" p278

The Annotated C++ Reference Manual

Etiketler:

Cumartesi, Temmuz 04, 2009

Diyelim ki bir nesneyi kendine gore ekrana bastirmak istiyorsun. Bu durumda ilk aklima gelen << operatorunu tanimlamakdi nesnenin icinde. Ama oyle olmadi. Disarida, main den once, << icin overload tanimliyorsun. Hani bir fonksiyonu farkli girisler icin cagirabilme durumu bu overload..

ostream & operator << (ostream & out, const IntCell & rhs)
{
out << "value=" << rhs.read();
return out;
}


Bir diger yaklasim da


friend ostream &operator<<(ostream &stream, IntCell & ob);

olarak public kisminda nesne icinde tanimlamak. Ancak Weiss kitabinda bunun eski derleyiciler tarafindan sorun cikardigini, bazan friend ile template leri birlestirmekte sorun yasandigini yaziyor.

Diger taraf icin:

istream &operator>>(istream &stream, IntCell &ob);


kullanilmali.

Etiketler:

Cuma, Temmuz 03, 2009

Sablonlu Fonksiyonlar (Function Templates)


#include <vector>
#include <iostream>

using namespace std;
/**
* Return the maximum of an array
* Assumes a.size() > 0
* Comparable objecs must provide operator< and operator=
*/

template <typename Comparable>
const Comparable & findMax(vector<Comparable> &a)
{
int maxIndex = 0;
for (int i=0; i < a.size(); i++)
if(a[maxIndex] < a[i] ) //operator < burada gerekli
maxIndex = i;
return a[maxIndex]; //operator= burada kullanilacak

}

int main()
{
vector<int> v1(7);
for (int i=0; i < v1.size(); i++)
v1[i] = i;
cout<< findMax(v1) << endl;
return 0;
}

Etiketler:

OpenSolaris de kod ayiklama :)

http://dlc.sun.com/osol/docs/content/OSOLINTROOS/docinfo.html

Etiketler:

C++ isim cozumlemesi

"using nm to extract the symbol table from a sample program named initcell produces the following output:"

nm intcell
0000200c D _NXArgc
00002008 D _NXArgv
00001e76 s __GLOBAL__I_main
00001e1e s __Z41__static_initialization_and_destruction_0ii
00001e0c T __ZN7IntCell5writeEi
00001dd8 T __ZN7IntCellC1ERKS_
00001d88 T __ZN7IntCellC1Ei
00001da8 T __ZN7IntCellaSERKS_
00001dfc T __ZNK7IntCell4readEv
U __ZNSolsEPFRSoS_E
U __ZNSolsEi
U __ZNSt8ios_base4InitC1Ev
U __ZNSt8ios_base4InitD1Ev
U __ZSt4cout
U __ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_
00002034 b __ZSt8__ioinit
U __Znwm
U ___cxa_atexit
U ___gxx_personality_v0
00002000 D ___progname
00001d66 t ___tcf_0
00001c4c t __dyld_func_lookup
00001000 A __mh_execute_header
00002004 D _environ
U _exit
00001c5a T _main
00002010 d dyld__mach_header
00001c38 t dyld_stub_binding_helper
00001bf8 T start

Etiketler:

Problemiin cozumu

IntCell(const IntCell & rhs)
{
storedValue = new int (*(rhs.storedValue)); //new ile dinamik yer al!
//
storedValue = new int (*rhs.storedValue);
}

Reason: KERN_PROTECTION_FAILURE at address: 0x00000000 gosteriyor ki storedValue isaretcisini ilk degeri null. Ama her zaman gecerli mi bilmiyorum. Eger baska bir yer olsaydi verinin ustune yaziyoruz demekti, hata hata...

Etiketler:

gdb

Bir onceki dosyalar make komutu ile derlenir: Make asagidaki komutlari uretip calistiracak.

g++ -ggdb -Wall -c IntCell.cpp
g++ -ggdb -Wall -o intcell IntCell.o

Komut satirindan ./intcell deyince Bus Error veriyor.

E ne yapcaz.

Komut satirindan:
gdb intcell
de.

Sonra
run

asagidakini uretir.

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_PROTECTION_FAILURE at address: 0x00000000
0x00001dfa in IntCell::IntCell (this=0xbffff888, rhs=@0xbffff88c) at IntCell.h:25
25 *storedValue = *(rhs.storedValue);
(gdb) where
#0 0x00001dfa in IntCell::IntCell (this=0xbffff888, rhs=@0xbffff88c) at IntCell.h:25
#1 0x00001c9e in main () at IntCell.cpp:7

Daha sonra
where

list main
list 25


vs diyerek programi anla.

Etiketler:

Ornek Kod Dosyasi


#include <iostream>
#include "IntCell.h"


int main(){

IntCell a = IntCell(2);
IntCell b = a; //copy constructor
IntCell c; //copy assigment operator


c=b;

a.write(4);
std::cout << a.read() << std::endl << b.read() << std::endl <<c.read() << std::endl;
return 0;

}

Etiketler:

Ornek Header File


IntCell.h:
#Bu hatali bir program. Amacim debug islemini ogrenmek

#ifndef _INTCELL_H_
#define _INTCELL_H_


class IntCell
{

public:
/**
* C++ eger tek bir constructor argumani varsa su sekilde yazilima izin veriyor:
* IntCell i = 6;
* Burada derleyici otomatik olarak temp bir IntCell yaratiyor. Atamayi yapiyor ve
* gecici degiskeni yok ediyor.
* explicit kelimesi bunu engellemek icin.
* Sadece IntCell i = IntCell(6);
* ya da IntCell i(6); diyerek yeni bir nesne yaratilabilir.
*/
explicit IntCell(int initValue=0)
{
storedValue = new int(initValue);
}

/**
* Destructor: use delete because the data stored is dynamically allocated
* using new
*/
~IntCell()
{
delete storedValue;
}
/**
* Bu iki IntCell nesneyi karsilastirmak icin
* Ileride verilen findMax icin gerekli bir operator
*/
bool operator<(const IntCell &rhs)
{
return *storedValue < *rhs.storedValue;
}

/**
* Copy assignment operator =
* This is applied to two objects after they have both been constructed
* lhs=rhs is intended to copy the state of rhs to lhs by default
*/

const IntCell & operator=(const IntCell &rhs)
{
if( this != &rhs)
{
storedValue = new int(*(rhs.storedValue));
}
return *this;
}

/**
* Copy constructor
* This constructor is called
* a - when a declaration with initialization is called , but not A=B (this is assignment op)
* b - an object is passed using call by value (instead of by & or const &)
* c - an object returned by value (instead of by & or const &)
*/

IntCell(const IntCell & rhs)
{
*storedValue = *(rhs.storedValue);
}

/**
* Read the stored value: accessor
*/

int read() const
{
return *storedValue;
}

/**
* Change the stored value: mutator
*/

void write(int x)
{
*storedValue = x;
}

private:
int *storedValue;

};

#endif

Etiketler:

Ornek Makefile

#
# Makefile for the Free Software Foundation's g++ compiler
#

CC=g++
CFLAGS=-g -Wall
SRC=IntCell.cpp IntCell.h
OBJ=IntCell.o

all:intcell

intcell:$(OBJ)
$(CC) $(CFLAGS) -o intcell $(OBJ)

IntCell.o: IntCell.h IntCell.cpp
$(CC) $(CFLAGS) -c IntCell.cpp

clean:
rm $(OBJ) intcell

Etiketler: ,

Perşembe, Temmuz 02, 2009

DTrace

# gcore `pgrep CCtest`
gcore: core.1478 dumped
# mdb core.1478
Loading modules: [ libc.so.1 ld.so.1 ]
> main::dis
main: pushl %ebp
main+1: movl %esp,%ebp
main+3: subl $0x38,%esp
main+6: movl %esp,-0x2c(%ebp)
main+9: movl %ebx,-0x30(%ebp)
main+0xc: movl %esi,-0x34(%ebp)
main+0xf: movl %edi,-0x38(%ebp)
main+0x12: pushl $0x8
main+0x14: call -0x2e4
main+0x19: addl $0x4,%esp
main+0x1c: movl %eax,-0x10(%ebp)
main+0x1f: movl -0x10(%ebp),%eax
main+0x22: pushl %eax
main+0x23: call +0x1d5 <__1cjtestclass2t5b6m_v_>

Etiketler:

new, delete kullanimi

void
F(int i)
{
int a[10];
int *b = new int[10]; // a ya esdegerlik icin const int *b diye tanimlamak daha dogru
// fonksiyondan geri douldugunde a dizisi icin atanan yer sisteme geri verilecek
// b isaretcisinin kapladigi alan da geri verilecek
// Ama b'nin isaret ettigi 10 int alan acikta kalacak --> leak
delete [] b; // Bu bellek problemini cozecek, iade edecek
}

Etiketler:

Çarşamba, Temmuz 01, 2009

Java Hashtable'dan Array

protected String[] hashToStringArray(Hashtable h)
throws NullPointerException {
Vector v = new Vector();

Enumeration e = h.keys();
while (e.hasMoreElements()) {
String k = e.nextElement();
v.add(h.get(k).toString());
}
String[] strArr = new String[v.size()];
v.copyInto(strArr);

return strArr;
}

Etiketler:

Nesne Tabanli Temel bir C++ programi

----- Node.h dosyasi ABSTRACT CLASS-----
#ifndef _NODE_H_
#define _NODE_H
class Node{
private:
Node(Node & oldNode); //Disable copy
public:
Node(){};
virtual void dump() const = 0; //pure virtual

};
#endif


---SimpleNode.h-----

#ifndef _SIMPLENODE_H
#define _SIMPLENODE_H

#include "Node.h"
#include <iostream>
// Node'dan turetiliyor.
class SimpleNode: public Node{
private:
const std::string data;
public:
SimpleNode(const std::string s): data(s){
}
void dump() const;

};
#endif

---SimpleNode.cpp dosyasi----

#include "SimpleNode.h"
#include <iostream> //cout icin gerekli

using namespace std;

void SimpleNode::dump() const{
cout << data;
}

int main(){
SimpleNode sn("Tete"); //Bir nesne yaratiyor!
SimpleNode *ns = new SimpleNode("Bu new kullanir, isaretci gonderir");
//Node n1=sn; //Bu hata verir. Cunku Node bir abstract nesne ve yaratilamaz.
Node *n = &sn;
Node &n2 = sn; //Burada n2 sn icin bir lakab (alias)
(*n).dump(); //Asagida alternatif bir yontem var.
n->dump();
n2.dump();
}

Etiketler: