본문 바로가기
C++

_countof 는 포인터로 하면 안된다.

by juheeL 2017. 6. 30.

_countof 에 


char[10] a;

_countof(a) 

하면 잘 되는데



char* b = a;

_countof(b)

하면 

컴파일 에러!



그래서

strcpy( str1, str2); 

->

strcpy(str1, _countof(str1), str2); 

사용할 때,


str1이 포인터 형태면 안된다.


그럼 어떻게 해결할까?




Remarks

Ensure that array is actually an array, not a pointer. In C, _countof will produce erroneous results if array is a pointer. In C++, _countofwill fail to compile if array is a pointer.





참조 : http://www.benjaminlog.com/entry/countof-macro


참조 : https://msdn.microsoft.com/en-us/library/ms175773(v=vs.80).aspx