Home #define vs typedef in C++
Post
Cancel

#define vs typedef in C++

#define vs typedef in C++

#define 란?

  • #define is just a search-and-replace mechanism, where the thing you define is literally substituted into the source code text before it’s even parsed.
  • #define is a preprocessor token: the compiler itself will never see it.
  • #define in C is a directive which is used to #define alias.
  • 컴파일이 되기전에 수행되는 선행처리기로 “치환” 하는 개념

typedef 란?

  • typedef defines a type (duh!) Just as for example is a built-in type, you can define your own, either as an alias for another type, or as an aggregate of existing types in a struct, or as a list of possible values (enum).
  • typedef is a compiler token: the preprocessor does not care about it.
  • The typedef is used to give data type a new name.
  • 새로운 자료형을 선언해주는 개념

#define vs typedef

  • #definetypedef
    값에 대해 alias를 정의 가능새로운 자료형 선언으로만 제한됨
    선행처리기에 의해 수행컴파일러에 의해 수행
    semicolon으로 끝나지 않음semicolon으로 끝남
    사용되는 시점에서 정의된 값을 가져다가 붙임새로운 자료형으로 사용됨
    No scope rule is followedtypedef can be defined within a scope

References

This post is licensed under CC BY 4.0 by the author.

깃허브 페이지에 파비콘 추가하기

CCW Algorithm