Contents
- 이 문서는
- program entry function
- float 사용을 피해라
- standard header 를 직접 include 하지 마라
- include 와 파일네임 사이에 /**/ 를 추가해라
- 매크로의 값을 수치비교 할때, 그것이 정의되어있는지 먼저 확인해라.
- pragma once 의 사용
- math.h 의 사용을 피해라
- 어쩌구.cpp 는 어쩌구.h 를 제일먼저 include 해라
- prefix operator 가 postfix operator 보다 빠르다.
- 인라인 함수는 *.i 에 작성하고, .h 가 .i 를 include 해라.
- ACE_NEW 와 ACE_NEW_RETURN 을 써라.
- 포인터가 널값인지 비교할때 NULL 을 쓰지 말고 0 을 써라
- 포인터와 int 간의 캐스팅은 하지 마라
- 수치 타입을 쓸때 조심해라
이 문서는
$(ACE_ROOT)\docs\ACE-guidelines.html 의 내용의 일부를 적은 것이다.
program entry function
main 함수는 다음의 세가지중 한가지를 쓸수 있다.
int main(int argc, char* argv[]) int wmain(int argc, wchar_t* argv[]) // win32 only int ACE_MAIN(int argc, ACE_TCHAR* argv[]) // ACE_USES_WCHAR 가 디파인되어있으면 wchar_t 가 된다.
main 함수는 성공시 0 을 실패시 0 이 아닌 정수를 리턴.
float 사용을 피해라
모든 ACE 플래폼이 float 연산을 지원하는것은 아니다. 음 내경우 이것은 별로 신경쓰지 않아도 되는데, ACE 의 경우 여러가지 플래폼을 지원해서 이런 형식의 권고가 많은 편이다. 나는 모든 ACE 플래폼에서 도는 코드를 만들생각은 없으니 이런 자잘한 권고안은 이 페이지에선 적지 않겠다. ACE 를 쓰는 이유가 완전히 플래폼 독립적인 코드를 위한거라면, 원문을 찾아서 읽어볼것.
standard header 를 직접 include 하지 마라
include 와 파일네임 사이에 /**/ 를 추가해라
This avoids dependency problems with Visual C++ and prevents Doxygen from including the headers in the file reference trees. 라고 되어있는데, 잘 모르겠군?
매크로의 값을 수치비교 할때, 그것이 정의되어있는지 먼저 확인해라.
#if __FreeBSD__ < 3 // __FreeBSD__ 가 정의되어 있지 않은경우 항상 true 가 된다. #if defined (__FreeBSD__) && __FreeBSD__ < 3
pragma once 의 사용
header 파일이 ACE 라이브러리 헤더를 인클루드 하고 있을경우 pragma once 를 해주는것이 좋다. 이런경우 header 의 가이드 매크로는 다음처럼 된다.
#ifndef FOO_H #define FOO_H #include "ace/ACE.h" #if !defined (ACE_LACKS_PRAGMA_ONCE) # pragma once #endif /* ACE_LACKS_PRAGMA_ONCE */ [contents of header file] #endif /* FOO_H */
pragma once 는 컴파일 시간을 줄이는데 쓰이는 것이니, 큰 프로젝트가 아니라면 무시해도 될것 같다.(이건 좀더 확인을...)
boost 의 메일링에서 따온 글 "#pragma once" is just an optimization issue. If a file is included a second time in the same TU, a dumb compiler will re-open it and give it to the preprocessor who strips its contents entirely because the include guard is already defined. Re-opening + preprocessing takes little but significant time. With the "#pragma once" the programmer just gives an hint to the compiler that re-opening is unnecessary and ignores the #include directive immediately. You see, there *is* a speed gain even in the presence of canonical include guards. Of course, a smarter compiler like g++ will recognize the canonical include guards and deduce that re-opening is unnecessary without any explicit hint given by the programmer.
math.h 의 사용을 피해라
SunOS 5.5.1 부터 5.7 까지는 math.h 가 exception 이라는 struct 를 선언해 놔서, std::exception 이랑 이름이 충돌할 가능성이 있댄다.
어쩌구.cpp 는 어쩌구.h 를 제일먼저 include 해라
prefix operator 가 postfix operator 보다 빠르다.
이건 effective c++ 에도 나온내용. 일반적으로 postfix 가 prefix 를 부르도록 구현되어 있기 때문이다.
++i 가 i++ 보다 좋다...
인라인 함수는 *.i 에 작성하고, .h 가 .i 를 include 해라.
헤더는,
class ACE_Export ACE_High_Res_Timer { [...] }; #if defined (__ACE_INLINE__) #include "ace/High_Res_Timer.i" #endif /* __ACE_INLINE__ */
.cpp 는
#define ACE_BUILD_DLL #include "ace/High_Res_Timer.h" #if !defined (__ACE_INLINE__) #include "ace/High_Res_Timer.i" #endif /* __ACE_INLINE__ */ ACE_ALLOC_HOOK_DEFINE(ACE_High_Res_Timer)
ACE_NEW 와 ACE_NEW_RETURN 을 써라.
할당이 성공인지 체크해주고, errno 를 세팅해준다.
포인터가 널값인지 비교할때 NULL 을 쓰지 말고 0 을 써라
NULL 값은 구현에 따라 달라지는 값이다.
포인터와 int 간의 캐스팅은 하지 마라
포인터를 캐스팅(to, from) 하려면, long 을 써라.
수치 타입을 쓸때 조심해라
long 은 모든 플래폼에서 4바이트인것이 아니다. ACE_UINT32 는 항상 4바이트, ACE_UINT64 는 항상 8바이트니 이런놈을 써라
음... 다적기가 애매하네 그냥 코딩전에 한번씩 훑어보는 식으로 해야 겠다.
