'typedef'에 해당되는 글 1건

  1. 2010.07.18 typedef
Objective C/C언어 기능2010. 7. 18. 17:40

 #### typedef : 프로그램안에서 내가 정의한 데이터 타입

 구조체를 제외한 대부분의 데이터 타입은 시스템에서 제공하는 기본 데이터 타입을 갖는다.

  기본 데이터 타입외에 나만의 데이터 타입을 만들기 위해서 typedef(type define) 사용한다.

 구조체도 데이터 프로토타입을 만들어 나만의 타입을 제공하지만 선언시 앞에 struct 프로토타입 이름을 붙여야 한다.

 typedef 사용하면 구조체에서 선언한 변수명을 데이터 타입으로 사용할 있다.




//date라는 변수명으로 sDate프로토 타입 선언하는 구조체

//구조체에 typedef 사용하여 변수 date 데이터 형으로 설정

typedef struct sDate {

int month;

int day;

int year;

} date;


//INT라는 변수명을 int데이터 형으로 설정

typedef int INT;


int main (int argc, const char * argv[]) {

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];


date today;

today.month = 6;

today.day = 15;

today.year = 2010;

NSLog(@"%i-%i-%i",today.month, today.day, today.year);

INT myInt = 100;

NSLog(@"%i", myInt);

    [pool drain];

    return 0;

}


Posted by 버터백통