매크로에 전달 된 매개 변수에 따라 정의 된 C 매크로를 선언하고 싶습니다. 즉, C 매크로에서 #if
지시어를 사용하고 싶습니다. 그것은 다음과 같이해야한다 :C 매크로에서 #if 지시문을 사용할 수 있습니까?
#define XLType_id 1
#define XLTypeCastToVoidPointer(type) #if XLType_##type \\
(__bridge void *)\\
#define XLTypeCast(type) (__bridge id)\\
#else \\
&\\
#define XLTypeCast(type) *(type*)\\
#endif
내가 사용하려는 XLTypeCastToVoidPointer()
및 (void *)
유형의 변수를 캐스트 다시 매크로 XLTypeCast()
.
- (NSInteger) value{
NSInteger returnValue = 100;
// the same as -> void *aValueToReturn = &returnValue;
void *aValueToReturn = XLTypeCastToVoidPointer(NSInteger) returnValue;
// Do something with this void pointer here.
// the same as -> return *(NSInteger*) aValueToReturn;
return XLTypeCast(NSInteger) aValueToReturn;
}
- (NSString*)string{
NSString* aString = @"a string";
// the same as -> void *aValueToReturn = &returnValue;
void *aValueToReturn = XLTypeCastToVoidPointer(id) aString;
// Do something with this void pointer here.
// the same as -> return *(NSInteger*) aValueToReturn;
return XLTypeCast(id) aString;
}
그러나 C 매크로에는 #if
지시문을 사용할 수 없습니다. 이 일을 할 수있는 방법이 있습니까?
같은 것을 멀리 얻을 수있는 하나의 토큰 식별자로 식별됩니다 만 (여기에 내가
bridge
및toto
사용) 유형의 작은 세트에 대해 정말 경우 아니, 당신은 할 수 있습니다 전처리 기 매크로에서 전 처리기 매크로를 정의하지 마십시오. –이렇게 할 수 없을뿐만 아니라 사전 처리 단계에서도 유형에 대해 알지 못합니다. 토큰 시퀀스에 대해서만 알고 있습니다. 아마도 당신이 달성하고자하는 것이 정확히 무엇인지 말해야합니까? –
나는 그렇게 생각하지 않는다. –