굳이 왜 const 키워드도 같이 있는거임? static 이야 메모리 영역에서 보면 static 영역에 저장되어 전역적으로 쓸 수 있겠다만 const는 아무리 생각해도 이해를 할수가 없네
댓글 9
깃헙이랑 뭔상관. 글고 Immutable쓰는건 여러 이점있음
익명(59.13)2021-01-31 07:12
답글
ㅈㅅ 내가 뇌가 잠깐 이상했나봄 제목 수정함
익명(211.36)2021-01-31 07:22
답글
constants are always fixed in size, and known at compile time.
Another, less obvious result, is that constants may not be of a type that requires allocation on the heap, since they’re not known at compile time. - dc App
파블로프_(pavlov2)2021-01-31 08:04
답글
Constants can be declared in any scope, including the global scope.
They are valid for the entire runtime of the program inside that scope. - dc App
파블로프_(pavlov2)2021-01-31 08:04
답글
러스트에서 그냥 let과 const 둘다 immutable이지만 const는 이런 차이점이 있네 - dc App
파블로프_(pavlov2)2021-01-31 08:06
let쓰면 나오는건 그냥 변수고 const쓸때만 상수라거 부름
Riey(rerereq)2021-01-31 10:16
답글
const는 let보다 static이랑 유사한데 차이점은 어디에도 할당되지 않고 매크로같이 교체됨 예를들어서 const FOO: Foo = Foo::new();라 하면 FOO를 쓰는 모든곳에서 Foo::new를 호출함 static은 한번만 부르고 값을 돌려쓰는거고
Riey(rerereq)2021-01-31 10:22
답글
ㄹㅇ?? const 값이 컴파일타임에 결정안돼도 상관없음?
Adenosie(adenosie)2021-01-31 12:39
답글
당연히 const context안 그러니까 컴파일 타임에 계산되는 값만 들어가는데 그걸 매번 계산해서 끼워넣냐 한번 계산해서 전역변수에 넣냐의 차이지
깃헙이랑 뭔상관. 글고 Immutable쓰는건 여러 이점있음
ㅈㅅ 내가 뇌가 잠깐 이상했나봄 제목 수정함
constants are always fixed in size, and known at compile time. Another, less obvious result, is that constants may not be of a type that requires allocation on the heap, since they’re not known at compile time. - dc App
Constants can be declared in any scope, including the global scope. They are valid for the entire runtime of the program inside that scope. - dc App
러스트에서 그냥 let과 const 둘다 immutable이지만 const는 이런 차이점이 있네 - dc App
let쓰면 나오는건 그냥 변수고 const쓸때만 상수라거 부름
const는 let보다 static이랑 유사한데 차이점은 어디에도 할당되지 않고 매크로같이 교체됨 예를들어서 const FOO: Foo = Foo::new();라 하면 FOO를 쓰는 모든곳에서 Foo::new를 호출함 static은 한번만 부르고 값을 돌려쓰는거고
ㄹㅇ?? const 값이 컴파일타임에 결정안돼도 상관없음?
당연히 const context안 그러니까 컴파일 타임에 계산되는 값만 들어가는데 그걸 매번 계산해서 끼워넣냐 한번 계산해서 전역변수에 넣냐의 차이지