C의 표준 유형에 대한 typedef에 대한 권장 접근 방식은 무엇입니까?C의 표준 유형에 대한 typedef에 대한 권장 접근법은 무엇입니까?
예를 들어 프로젝트 시작시 가능한 가장 작은 유형의 typedef를 만들었습니다. 주된 의도는 전체 프로젝트에서 전역 검색 + 바꾸기를 수행하지 않고도 사용 된 숫자 범위가 유형에 비해 너무 큰 경우 유형을 쉽게 수정할 수 있도록하는 것이 었습니다. 그러나 6 개월 후 나는 만족스럽지 않고 더 나은 방법이 있어야한다고 생각한다.
이 내가 정의한 유형은 다음과 같습니다 덜 T_MAX
내가 '하지만 max_val
이 어디
/* type to be used for storing map data within
n*n array */
typedef unsigned char map_t;
/* type to be used for storing coordinates in map.
min 0,max 32 (MAP_W,MAP_H defaults). note: no
longer requires signed. */
typedef unsigned char xy_t;
/* type to be used for counters, ie moves_remaining
has max 2000 */
typedef signed int ctr_t;
/* type to be used for storing the level number,
requires signed. */
typedef signed short lvl_t;
/* type to be used for storing contact types,
see actions.h CONTACT */
typedef signed short ct_t;
/* small unsigned type, miscellaneous */
typedef unsigned char su_t;
/* small signed type, miscellaneous */
typedef signed char ss_t;
struct xy
{
xy_t x;
xy_t y;
};
struct scrxy
{
int x;
int y;
};
struct xy_offset
{
ss_t x;
ss_t y;
};
대신 서명 유형을 사용하고 n < 0 && n > max_val
에 대한 검사의 일부 코드는 부호없는 형식과 n > max_val
에 대해서만 검사를 사용 이 동작은 실제로 정의되지 않았 음을 알게 된 이후로
typedef
을 모두 제거하고 내 코드 전체에서 stdint.h
에 정의 된 표준 유형을 사용해야하나요? (크기가 현재 상당히 안정되었습니다)?
당신이 "발견이 동작은 실제로 정의되지 않은 때문에"당신이 말할 때 참조 무엇 http://groups.google.com/group/comp.compilers/msg/c0797b5b668605b4?pli=1 – adatapost
에서보세요 ? – caf
@caf : 부호없는 저장소 유형에 -1을 할당하면 결과가 해당 형식의 최대 값이되는 경우가 많지만 C 표준에 정의되어 있지 않으므로 보장되지 않습니다. –