我在声明和使用静态变量时收到警告。
static int m_chSequenceChar;
@interface data : NSObject
{
}
-(id)init;
-(void)initialze;
@end
@implementation data
- (id)init
{
m_chSequenceChar= 0;
}
+ (void)initialize
{
m_chSequenceChar= 0;
}
@end
警告:'m_chSequenceChar'已定义 但未使用
编辑:
data.h
------
static int m_nMessageId; //Message ID
static int m_uSessionId; //Session ID
static int m_chSequenceChar; //Sequence ID
static int* m_pData; //Integer buffer to carry data
static int m_uDataSize; //Datasize
@interface data : NSObject {
@public
}
data.m
------
@implementation data
+ (void)initialize
{
m_uSessionId = 0;
m_chSequenceChar= 0;
m_nMessageId = 0;
m_pData = 0;
m_uDataSize = 0;
}
- (id) initWithID:(int) uMessageId withData:(id)pData withSize:(size_t) uDataSize
{
if(self=[super init])
{
// Initialize the member variables
m_uSessionId = 0xFF;
m_chSequenceChar= 10;
// Initialize values from derived class
m_nMessageId = uMessageId;
m_pData = (int*)pData;
m_uDataSize = (int)uDataSize;
}
NSLog(@"Data size:%d",uDataSize);
NSLog(@"m_pData:%d",m_pData);
NSLog(@"pData:%d",pData);
data* dat = [data alloc];
return self;
}
@end
答案 0 :(得分:1)
那是因为您没有在代码中读取m_chSequenceChar
的值。如果你没有阅读它,你就不会使用它,因此就是警告。
此外,如果m_chSequenceChar
的实例收到0
,您确定要将data
重置为-init
吗?通常,+initialize
应该足够了。而且,实际上,您甚至不需要将其明确设置为0
。